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}/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/{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") 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}/versions/{artifact-version}") public void getArtifactInfo(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 Exception { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion); try { ArtifactDetail detail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId)); ArtifactDescriptor descriptor = detail.getDescriptor(); // info hides some fields that are available in detail, such as the location of the artifact ArtifactInfo info = new ArtifactInfo(descriptor.getArtifactId(), detail.getMeta().getClasses(), detail.getMeta().getProperties(), detail.getMeta().getUsableBy()); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(info, ArtifactInfo.class)); } 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}/artifacts/{artifact-name}/versions/{artifact-version}") public void getArtifactInfo(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 Exception { NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope); ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion); try { ArtifactDetail detail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId)); ArtifactDescriptor descriptor = detail.getDescriptor(); // info hides some fields that are available in detail, such as the location of the artifact ArtifactInfo info = new ArtifactInfo(descriptor.getArtifactId(), detail.getMeta().getClasses(), detail.getMeta().getProperties(), detail.getMeta().getUsableBy()); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(info, ArtifactInfo.class)); } 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."); } }
@Test public void testRevokeOnNonExistingEntity() throws FeatureDisabledException, UnauthenticatedException, UnauthorizedException, IOException, NotFoundException { // revoke on non exiting entities should work fine client.revoke(Authorizable.fromEntityId(Ids.namespace("ns3")), admin, ImmutableSet.of(Action.ADMIN)); }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, Set<ArtifactRange> parents, @Nullable Set<PluginClass> additionalPlugins, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Manifest manifest = createManifest(pluginClass, pluginClasses); final Location appJar = PluginJarHelper.createPluginJar(locationFactory, manifest, pluginClass, pluginClasses); artifactClient.add( Ids.namespace(artifactId.getNamespace()), artifactId.getArtifact(), appJar::getInputStream, artifactId.getVersion(), parents, additionalPlugins ); appJar.delete(); return new RemoteArtifactManager(clientConfig, restClient, artifactId); }
@Test public void testRevokeAllOnNonExistingEntity() throws Exception { // revoke on non existing entities should work fine client.revoke(Authorizable.fromEntityId(Ids.namespace("ns3"))); }
private LoggingContext createLoggingContext(ProgramId programId, RunId runId, @Nullable WorkflowProgramInfo workflowProgramInfo) { if (workflowProgramInfo == null) { return new SparkLoggingContext(programId.getNamespace(), programId.getApplication(), programId.getProgram(), runId.getId()); } ProgramId workflowProramId = Ids.namespace(programId.getNamespace()).app(programId.getApplication()) .workflow(workflowProgramInfo.getName()); return new WorkflowProgramLoggingContext(workflowProramId.getNamespace(), workflowProramId.getApplication(), workflowProramId.getProgram(), workflowProgramInfo.getRunId().getId(), ProgramType.SPARK, programId.getProgram(), runId.getId()); }
private LoggingContext createLoggingContext(ProgramId programId, RunId runId, @Nullable WorkflowProgramInfo workflowProgramInfo) { if (workflowProgramInfo == null) { return new SparkLoggingContext(programId.getNamespace(), programId.getApplication(), programId.getProgram(), runId.getId()); } ProgramId workflowProramId = Ids.namespace(programId.getNamespace()).app(programId.getApplication()) .workflow(workflowProgramInfo.getName()); return new WorkflowProgramLoggingContext(workflowProramId.getNamespace(), workflowProramId.getApplication(), workflowProramId.getProgram(), workflowProgramInfo.getRunId().getId(), ProgramType.SPARK, programId.getProgram(), runId.getId()); }
private LoggingContext createLoggingContext(ProgramId programId, RunId runId, @Nullable WorkflowProgramInfo workflowProgramInfo) { if (workflowProgramInfo == null) { return new SparkLoggingContext(programId.getNamespace(), programId.getApplication(), programId.getProgram(), runId.getId()); } ProgramId workflowProramId = Ids.namespace(programId.getNamespace()).app(programId.getApplication()) .workflow(workflowProgramInfo.getName()); return new WorkflowProgramLoggingContext(workflowProramId.getNamespace(), workflowProramId.getApplication(), workflowProramId.getProgram(), workflowProgramInfo.getRunId().getId(), ProgramType.SPARK, programId.getProgram(), runId.getId()); }
@Test public void testGetNonexistantArtifact() throws IOException { NamespaceId namespace = Ids.namespace("ns1"); // no artifacts in a namespace should return an empty collection Assert.assertTrue(artifactStore.getArtifacts(namespace).isEmpty()); // no artifacts in range should return an empty collection ArtifactRange range = new ArtifactRange( namespace.getNamespace(), "something", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")); Assert.assertTrue(artifactStore.getArtifacts(range, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED).isEmpty()); // no artifact by namespace and artifact name should throw an exception try { artifactStore.getArtifacts(namespace, "something", Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED); Assert.fail(); } catch (ArtifactNotFoundException e) { // expected } // no artifact by namespace, artifact name, and version should throw an exception try { artifactStore.getArtifact(Id.Artifact.from(Id.Namespace.fromEntityId(namespace), "something", "1.0.0")); Assert.fail(); } catch (ArtifactNotFoundException e) { // expected } }