public ProgramId(ApplicationId appId, ProgramType type, String program) { super(appId.getNamespace(), EntityType.PROGRAM); if (type == null) { throw new NullPointerException("Program type cannot be null."); } if (program == null) { throw new NullPointerException("Program ID cannot be null."); } this.application = appId.getApplication(); this.version = appId.getVersion(); this.type = type; this.program = program; }
private ApplicationSpecification getAppSpecOrFail(AppMetadataStore mds, ApplicationId id) { ApplicationSpecification appSpec = getApplicationSpec(mds, id); if (appSpec == null) { throw new NoSuchElementException("no such application @ namespace id: " + id.getNamespaceId() + ", app id: " + id.getApplication()); } return appSpec; }
private ProgramId deserializeProgramId(JsonObject id) { ApplicationId app = deserializeApplicationId(id); ProgramType programType = ProgramType.valueOf(id.get("type").getAsString().toUpperCase()); String programId = id.get("program").getAsString(); return new ProgramId(app.getNamespace(), app.getApplication(), programType, programId); }
private ScheduleId deserializeSchedule(JsonObject id) { ApplicationId app = deserializeApplicationId(id); String scheduleId = id.get("schedule").getAsString(); return new ScheduleId(app.getNamespace(), app.getApplication(), app.getVersion(), scheduleId); }
@Override public void removeApplication(ApplicationId id) { LOG.trace("Removing application: namespace: {}, application: {}", id.getNamespace(), id.getApplication()); Transactionals.execute(transactional, context -> { AppMetadataStore metaStore = getAppMetadataStore(context); metaStore.deleteApplication(id.getNamespace(), id.getApplication(), id.getVersion()); metaStore.deleteProgramHistory(id.getNamespace(), id.getApplication(), id.getVersion()); }); }
@Override public void startProgram(ProgramId programId, Map<String, String> arguments) { try { appFabricClient.startProgram(application.getNamespace(), application.getApplication(), application.getVersion(), programId.getProgram(), programId.getType(), arguments); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public Collection<ApplicationId> getAllAppVersionsAppIds(ApplicationId id) { return Transactionals.execute(transactional, context -> { return getAppMetadataStore(context).getAllAppVersionsAppIds(id.getNamespace(), id.getApplication()); }); }
private ApplicationSpecification getApplicationSpec(AppMetadataStore mds, ApplicationId id) { ApplicationMeta meta = mds.getApplication(id.getNamespace(), id.getApplication(), id.getVersion()); return meta == null ? null : meta.getSpec(); }
@Override public void stopProgram(ProgramId programId) { String programName = programId.getProgram(); try { appFabricClient.stopProgram(application.getNamespace(), application.getApplication(), application.getVersion(), programName, programId.getType()); waitForStopped(programId); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void addApplication(ApplicationId id, ApplicationSpecification spec) { Transactionals.execute(transactional, context -> { getAppMetadataStore(context).writeApplication(id.getNamespace(), id.getApplication(), id.getVersion(), spec); }); }
protected MDSKey.Builder getApplicationKeyBuilder(String recordType, @Nullable ApplicationId applicationId) { MDSKey.Builder builder = new MDSKey.Builder().add(recordType); if (applicationId != null) { builder.add(applicationId.getNamespace()); builder.add(applicationId.getApplication()); builder.add(applicationId.getVersion()); } return builder; }
@Override public void remove(ApplicationId applicationId) { byte[] startRowKey = new MDSKey.Builder().add(applicationId.getNamespace()) .add(applicationId.getApplication()).build().getKey(); byte[] stopRowKey = new MDSKey(Bytes.stopKeyForPrefix(startRowKey)).getKey(); try { table.deleteRange(startRowKey, stopRowKey, null, null); } catch (IOException e) { String message = String.format("Error while removing preview data for application '%s'.", applicationId); throw new RuntimeException(message, e); } }
public void deleteApplication(ApplicationId appId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format("%s/apps/%s/versions/%s", getNamespacePath(appId.getNamespace()), appId.getApplication(), appId.getVersion())); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.deleteApp(request, mockResponder, appId.getNamespace(), appId.getApplication()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Deleting app failed"); }
public ApplicationDetail getInfo(ApplicationId appId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s", getNamespacePath(appId.getNamespace()), appId.getApplication()) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.getAppInfo(request, mockResponder, appId.getNamespace(), appId.getApplication()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting app info failed"); return mockResponder.decodeResponseContent(new TypeToken<ApplicationDetail>() { }.getType(), GSON); }
public Collection<String> listAppVersions(ApplicationId appId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s/versions", getNamespacePath(appId.getNamespace()), appId.getApplication()) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.listAppVersions(request, mockResponder, appId.getNamespace(), appId.getApplication()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Failed to list application versions"); return mockResponder.decodeResponseContent(new TypeToken<Collection<String>>() { }.getType(), GSON); }
public List<PluginInstanceDetail> getPlugins(ApplicationId application) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s", getNamespacePath(application.getNamespace()), application.getApplication()) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.getPluginsInfo(request, mockResponder, application.getNamespace(), application.getApplication()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting app info failed"); return mockResponder.decodeResponseContent(new TypeToken<List<PluginInstanceDetail>>() { }.getType(), GSON); }
protected HttpResponse deploy(ApplicationId appId, AppRequest<? extends Config> appRequest) throws Exception { String deployPath = getVersionedAPIPath(String.format("apps/%s/versions/%s/create", appId.getApplication(), appId.getVersion()), appId.getNamespace()); return executeDeploy(HttpRequest.post(getEndPoint(deployPath).toURL()), appRequest); }
protected void deleteApp(ApplicationId app, int expectedResponseCode) throws Exception { HttpResponse response = doDelete(getVersionedAPIPath( String.format("/apps/%s/versions/%s", app.getApplication(), app.getVersion()), app.getNamespace())); Assert.assertEquals(expectedResponseCode, response.getResponseCode()); }
public void delete(ApplicationId id) { MDSKey mdsKey = new MDSKey.Builder().add(id.getNamespace()).add(id.getApplication()).build(); Scanner scanner = table.scan(mdsKey.getKey(), Bytes.stopKeyForPrefix(mdsKey.getKey())); Row row; try { while ((row = scanner.next()) != null) { table.delete(row.getRow()); } } finally { scanner.close(); } }
@Test public void testAppFromArtifact() throws Exception { ArtifactId artifactId = NamespaceId.DEFAULT.artifact("cfg-app", "1.0.0-SNAPSHOT"); addAppArtifact(artifactId, ConfigTestApp.class); ApplicationId appId = NamespaceId.DEFAULT.app("AppFromArtifact"); AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>( new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("testStream", "testDataset") ); ApplicationManager appManager = deployApplication(appId, createRequest); testAppConfig(appId.getApplication(), appManager, createRequest.getConfig()); }