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; }
@Override public Collection<ApplicationSpecification> getAllAppVersions(ApplicationId id) { return Transactionals.execute(transactional, context -> { return getAppMetadataStore(context).getAllAppVersions(id.getNamespace(), id.getApplication()).stream() .map(ApplicationMeta::getSpec).collect(Collectors.toList()); }); }
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()); }); }
private boolean isInState(ProgramId programId, ProgramStatus status) { try { String actual = appFabricClient.getStatus(application.getNamespace(), programId.getApplication(), programId.getVersion(), programId.getProgram(), programId.getType()); return status.name().equals(actual); } catch (Exception e) { throw Throwables.propagate(e); } }
private boolean isInState(ProgramId programId, ProgramStatus status) { try { String actual = appFabricClient.getStatus(application.getNamespace(), programId.getApplication(), programId.getVersion(), programId.getProgram(), programId.getType()); return status.name().equals(actual); } 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); } }
@Nullable public ApplicationMeta getApplication(ApplicationId appId) { return getFirst(new MDSKey.Builder().add(TYPE_APP_META, appId.getNamespace(), appId.getApplication(), appId.getVersion()).build(), ApplicationMeta.class); }
@Override public void addApplication(ApplicationId id, ApplicationSpecification spec) { Transactionals.execute(transactional, context -> { getAppMetadataStore(context).writeApplication(id.getNamespace(), id.getApplication(), id.getVersion(), spec); }); }
@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); }
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 addSchedule(ApplicationId application, ScheduleDetail scheduleDetail) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/versions/%s/schedules/%s", getNamespacePath(application.getNamespace()), application.getApplication(), application.getVersion(), scheduleDetail.getName()); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri); request.content().writeCharSequence(GSON.toJson(scheduleDetail), StandardCharsets.UTF_8); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.addSchedule(request, responder, application.getNamespace(), application.getApplication(), application.getVersion(), scheduleDetail.getName()); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Add schedule failed"); }
public void deleteSchedule(ScheduleId scheduleId) throws Exception { MockResponder responder = new MockResponder(); ApplicationId application = scheduleId.getParent(); String uri = String.format("%s/apps/%s/versions/%s/schedules/%s", getNamespacePath(application.getNamespace()), application.getApplication(), application.getVersion(), scheduleId.getSchedule()); HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, uri); programLifecycleHttpHandler.deleteSchedule(request, responder, application.getNamespace(), application.getApplication(), application.getVersion(), scheduleId.getSchedule()); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Delete schedule failed"); } }
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(); } }
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(); } }