private NamespaceId validateAndGetNamespace(String namespaceId) throws NamespaceNotFoundException { return validateAndGetScopedNamespace(Ids.namespace(namespaceId), ArtifactScope.USER); }
private NamespaceId validateAndGetNamespace(String namespaceId) throws NamespaceNotFoundException { return validateAndGetScopedNamespace(Ids.namespace(namespaceId), ArtifactScope.USER); }
@GET @Path("/routeconfig") public void getRouteConfig(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("service-id") String serviceId) throws Exception { ProgramId programId = Ids.namespace(namespaceId).app(appId).service(serviceId); RouteConfig routeConfig = routeStore.fetch(programId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(routeConfig.getRoutes())); }
@GET @Path("/routeconfig") public void getRouteConfig(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("service-id") String serviceId) throws Exception { ProgramId programId = Ids.namespace(namespaceId).app(appId).service(serviceId); RouteConfig routeConfig = routeStore.fetch(programId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(routeConfig.getRoutes())); }
@GET @Path("/namespaces/{namespace-id}/classes/apps/{classname}") public void getApplicationClasses(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("classname") String className, @QueryParam("scope") @DefaultValue("user") String scope) throws NamespaceNotFoundException, BadRequestException { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); try { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getApplicationClasses(namespace, className), APPCLASS_INFOS_TYPE)); } catch (IOException e) { LOG.error("Error getting app classes for namespace {}.", namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading app class information from store, please try again."); } }
@GET @Path("/namespaces/{namespace-id}/classes/apps/{classname}") public void getApplicationClasses(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("classname") String className, @QueryParam("scope") @DefaultValue("user") String scope) throws NamespaceNotFoundException, BadRequestException { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); try { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getApplicationClasses(namespace, className), APPCLASS_INFOS_TYPE)); } catch (IOException e) { LOG.error("Error getting app classes for namespace {}.", namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading app class information from store, please try again."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/extensions") public void getArtifactPluginTypes(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @QueryParam("scope") @DefaultValue("user") String scope) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException { NamespaceId namespace = Ids.namespace(namespaceId); NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope); ArtifactId artifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion); try { SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = artifactRepository.getPlugins(namespace, Id.Artifact.fromEntityId(artifactId)); Set<String> pluginTypes = Sets.newHashSet(); for (Set<PluginClass> pluginClasses : plugins.values()) { for (PluginClass pluginClass : pluginClasses) { pluginTypes.add(pluginClass.getType()); } } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(pluginTypes)); } catch (IOException e) { LOG.error("Exception looking up plugins for artifact {}", artifactId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties/{property}") public void getProperty(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("property") String key, @QueryParam("scope") @DefaultValue("user") String scope) throws Exception { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion); try { ArtifactDetail detail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId)); responder.sendString(HttpResponseStatus.OK, detail.getMeta().getProperties().get(key)); } catch (IOException e) { LOG.error("Exception reading property for artifact {}.", artifactId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading properties for artifact."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties") public void getProperties(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @QueryParam("scope") @DefaultValue("user") String scope, @QueryParam("keys") @Nullable String keys) throws Exception { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion); try { ArtifactDetail artifactDetail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId)); Map<String, String> properties = artifactDetail.getMeta().getProperties(); Map<String, String> result; if (keys != null && !keys.isEmpty()) { result = new HashMap<>(); for (String key : Splitter.on(',').trimResults().split(keys)) { result.put(key, properties.get(key)); } } else { result = properties; } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result)); } catch (IOException e) { LOG.error("Exception reading artifacts named {} for namespace {} from the store.", artifactName, namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact properties from the store."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties/{property}") public void getProperty(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("property") String key, @QueryParam("scope") @DefaultValue("user") String scope) throws Exception { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion); try { ArtifactDetail detail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId)); responder.sendString(HttpResponseStatus.OK, detail.getMeta().getProperties().get(key)); } catch (IOException e) { LOG.error("Exception reading property for artifact {}.", artifactId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading properties for artifact."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties") public void getProperties(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @QueryParam("scope") @DefaultValue("user") String scope, @QueryParam("keys") @Nullable String keys) throws Exception { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion); try { ArtifactDetail artifactDetail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId)); Map<String, String> properties = artifactDetail.getMeta().getProperties(); Map<String, String> result; if (keys != null && !keys.isEmpty()) { result = new HashMap<>(); for (String key : Splitter.on(',').trimResults().split(keys)) { result.put(key, properties.get(key)); } } else { result = properties; } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result)); } catch (IOException e) { LOG.error("Exception reading artifacts named {} for namespace {} from the store.", artifactName, namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact properties from the store."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/extensions") public void getArtifactPluginTypes(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @QueryParam("scope") @DefaultValue("user") String scope) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException { NamespaceId namespace = Ids.namespace(namespaceId); NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope); ArtifactId artifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion); try { SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = artifactRepository.getPlugins(namespace, Id.Artifact.fromEntityId(artifactId)); Set<String> pluginTypes = Sets.newHashSet(); for (Set<PluginClass> pluginClasses : plugins.values()) { for (PluginClass pluginClass : pluginClasses) { pluginTypes.add(pluginClass.getType()); } } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(pluginTypes)); } catch (IOException e) { LOG.error("Exception looking up plugins for artifact {}", artifactId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts") public void getArtifacts(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @Nullable @QueryParam("scope") String scope) throws Exception { try { if (scope == null) { NamespaceId namespace = validateAndGetNamespace(namespaceId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, true))); } else { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, false))); } } catch (IOException e) { LOG.error("Exception reading artifact metadata for namespace {} from the store.", namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts") public void getArtifacts(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @Nullable @QueryParam("scope") String scope) throws Exception { try { if (scope == null) { NamespaceId namespace = validateAndGetNamespace(namespaceId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, true))); } else { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, false))); } } catch (IOException e) { LOG.error("Exception reading artifact metadata for namespace {} from the store.", namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts/{artifact-name}") public void getArtifactVersions(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @QueryParam("scope") @DefaultValue("user") String scope, @QueryParam("artifactVersion") String versionRange, @QueryParam("limit") @DefaultValue("2147483647") String limit, @QueryParam("order") @DefaultValue("UNORDERED") String order) throws Exception { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); ArtifactRange range = versionRange == null ? null : new ArtifactRange(namespaceId, artifactName, ArtifactVersionRange.parse(versionRange)); int limitNumber = Integer.parseInt(limit); limitNumber = limitNumber <= 0 ? Integer.MAX_VALUE : limitNumber; ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order); try { if (range == null) { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, artifactName, limitNumber, sortOrder))); } else { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(range, limitNumber, sortOrder))); } } catch (IOException e) { LOG.error("Exception reading artifacts named {} for namespace {} from the store.", artifactName, namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store."); } }
@GET @Path("/namespaces/{namespace-id}/classes/apps") public void getApplicationClasses(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @Nullable @QueryParam("scope") String scope) throws NamespaceNotFoundException, BadRequestException { try { if (scope == null) { NamespaceId namespace = validateAndGetNamespace(namespaceId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getApplicationClasses(namespace, true), APPCLASS_SUMMARIES_TYPE)); } else { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getApplicationClasses(namespace, false), APPCLASS_SUMMARIES_TYPE)); } } catch (IOException e) { LOG.error("Error getting app classes for namespace {}.", namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading app class information from store, please try again."); } }
@GET @Path("/namespaces/{namespace-id}/classes/apps") public void getApplicationClasses(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @Nullable @QueryParam("scope") String scope) throws NamespaceNotFoundException, BadRequestException { try { if (scope == null) { NamespaceId namespace = validateAndGetNamespace(namespaceId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getApplicationClasses(namespace, true), APPCLASS_SUMMARIES_TYPE)); } else { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getApplicationClasses(namespace, false), APPCLASS_SUMMARIES_TYPE)); } } catch (IOException e) { LOG.error("Error getting app classes for namespace {}.", namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading app class information from store, please try again."); } }
@GET @Path("/namespaces/{namespace-id}/artifacts/{artifact-name}") public void getArtifactVersions(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @QueryParam("scope") @DefaultValue("user") String scope, @QueryParam("artifactVersion") String versionRange, @QueryParam("limit") @DefaultValue("2147483647") String limit, @QueryParam("order") @DefaultValue("UNORDERED") String order) throws Exception { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); ArtifactRange range = versionRange == null ? null : new ArtifactRange(namespaceId, artifactName, ArtifactVersionRange.parse(versionRange)); int limitNumber = Integer.parseInt(limit); limitNumber = limitNumber <= 0 ? Integer.MAX_VALUE : limitNumber; ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order); try { if (range == null) { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, artifactName, limitNumber, sortOrder))); } else { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(range, limitNumber, sortOrder))); } } catch (IOException e) { LOG.error("Exception reading artifacts named {} for namespace {} from the store.", artifactName, namespaceId, e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store."); } }
NamespaceId namespace = Ids.namespace(namespaceId); NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope); ArtifactId artifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
NamespaceId namespace = Ids.namespace(namespaceId); NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope); ArtifactId artifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);