@Override public ProgramStatusTrigger build(String namespace, String applicationName, String applicationVersion) { // Inherit environment attributes from the deployed application ProgramId programId = new ApplicationId(namespace, applicationName, applicationVersion).program(programType, programName); return new ProgramStatusTrigger(programId, programStatuses); } }
@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 ServiceManager getServiceManager(String serviceName) { ProgramId programId = application.service(serviceName); return new DefaultServiceManager(programId, appFabricClient, discoveryServiceClient, this, metricsManager); }
public Collection<String> getAppVersions(String namespace, String application) throws Exception { Collection<ApplicationId> appIds = store.getAllAppVersionsAppIds(new ApplicationId(namespace, application)); List<String> versions = new ArrayList<>(); for (ApplicationId appId : appIds) { versions.add(appId.getVersion()); } return versions; }
@Test public void testProgramId() throws Exception { ProgramId serviceId = new ApplicationId("ns", "app").service("s1"); String discoverableName = ServiceDiscoverable.getName(serviceId); Assert.assertEquals("service.ns.app.s1", discoverableName); Assert.assertTrue(ServiceDiscoverable.isUserService(discoverableName)); Assert.assertFalse(ServiceDiscoverable.isUserService("service1.")); Assert.assertEquals(serviceId, ServiceDiscoverable.getId(discoverableName)); } }
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 void doDeleteSchedule(HttpResponder responder, String namespaceId, String appName, String appVersion, String scheduleName) throws Exception { ScheduleId scheduleId = new ApplicationId(namespaceId, appName, appVersion).schedule(scheduleName); programScheduleService.delete(scheduleId); responder.sendStatus(HttpResponseStatus.OK); }
private void registerDatasets(ApplicationWithPrograms input) { ApplicationSpecification appSpec = input.getSpecification(); ApplicationId appId = input.getApplicationId(); NamespaceId namespaceId = appId.getParent(); for (MapReduceSpecification program : appSpec.getMapReduce().values()) { ProgramId programId = appId.mr(program.getName()); for (String dataset : program.getDataSets()) { usageRegistry.register(programId, namespaceId.dataset(dataset)); } } for (SparkSpecification sparkSpec : appSpec.getSpark().values()) { ProgramId programId = appId.spark(sparkSpec.getName()); for (String dataset : sparkSpec.getDatasets()) { usageRegistry.register(programId, namespaceId.dataset(dataset)); } } for (ServiceSpecification serviceSpecification : appSpec.getServices().values()) { ProgramId programId = appId.service(serviceSpecification.getName()); for (HttpServiceHandlerSpecification handlerSpecification : serviceSpecification.getHandlers().values()) { for (String dataset : handlerSpecification.getDatasets()) { usageRegistry.register(programId, namespaceId.dataset(dataset)); } } } } }
@Test public void testGetProgramProfile() { ProfileId profileId = NamespaceId.DEFAULT.profile("p"); Map<String, String> args = Collections.singletonMap(SystemArguments.PROFILE_NAME, profileId.getScopedName()); ApplicationId appId = NamespaceId.DEFAULT.app("a"); ProgramId mrId = appId.mr("mr"); ProgramId serviceId = appId.service("serv"); ProgramId sparkId = appId.spark("spark"); ProgramId workerId = appId.worker("worker"); ProgramId workflowID = appId.workflow("wf"); Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(mrId, args)); Assert.assertEquals(ProfileId.NATIVE, SystemArguments.getProfileIdForProgram(serviceId, args)); Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(sparkId, args)); Assert.assertEquals(ProfileId.NATIVE, SystemArguments.getProfileIdForProgram(workerId, args)); Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(workflowID, args)); }
@Override public WorkflowManager getWorkflowManager(String workflowName) { WorkflowId programId = application.workflow(workflowName); return new RemoteWorkflowManager(programId, clientConfig, restClient, this); }
private Set<ProgramId> getProgramsWithType(ApplicationId appId, ProgramType type, Map<String, ? extends ProgramSpecification> programSpecs) { Set<ProgramId> result = new HashSet<>(); for (String programName : programSpecs.keySet()) { result.add(appId.program(type, programName)); } return result; }
@Test public void testGetTargetTypeChild() { ApplicationId expectedAppId = new ApplicationId("ns1", "app1"); MDSKey mdsValueKey = MetadataKey.createValueRowKey(expectedAppId.toMetadataEntity(), "key1"); ProgramId expectedProgramId = expectedAppId.spark("spark1"); MDSKey mdsValueKey2 = MetadataKey.createValueRowKey(expectedProgramId.toMetadataEntity(), "key2"); // assert that the key for parent child are independent and correct MetadataEntity actualAppId = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey()); Assert.assertEquals(expectedAppId.toMetadataEntity(), actualAppId); MetadataEntity actualProgramId = MetadataKey.extractMetadataEntityFromKey(mdsValueKey2.getKey()); Assert.assertEquals(expectedProgramId.toMetadataEntity(), actualProgramId); }
@Test public void testGetMetadataEntityFromKey() { ApplicationId expectedAppId = new ApplicationId("ns1", "app1"); MDSKey mdsValueKey = MetadataKey.createValueRowKey(expectedAppId.toMetadataEntity(), "key1"); MDSKey mdsIndexKey = MetadataKey.createIndexRowKey(expectedAppId.toMetadataEntity(), "key1", "value1"); // check that we can get MetadataEntity from value and index key MetadataEntity actualAppId = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey()); Assert.assertEquals(expectedAppId.toMetadataEntity(), actualAppId); actualAppId = MetadataKey.extractMetadataEntityFromKey(mdsIndexKey.getKey()); Assert.assertEquals(expectedAppId.toMetadataEntity(), actualAppId); }
@Override public ProgramId getId() { return new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "dummyApp").worker("dummy"); }
FlowletId flowlet = appId.flow(flowId).flowlet(flowletName); instances = programClient.getFlowletInstances(flowlet); break; ProgramId worker = appId.worker(workerId); instances = programClient.getWorkerInstances(worker); break; instances = programClient.getServiceInstances(appId.service(serviceName)); break; default:
ProgramId workerId = appId.worker(workerName); programClient.setWorkerInstances(workerId, numInstances); output.printf("Successfully set worker '%s' of app '%s' to %d instances\n", workerName, appId.getEntityName(), numInstances); break; case SERVICE: ServiceId service = appId.service(serviceName); programClient.setServiceInstances(service, numInstances); output.printf("Successfully set service '%s' of app '%s' to %d instances\n", serviceName, appId.getEntityName(), numInstances); break; default:
ProgramId worker = appId.worker(AppWithProgramsUsingGuava.NoOpWorker.NAME); startProgram(Id.Program.fromEntityId(worker)); waitForRuns(1, worker, ProgramRunStatus.FAILED); ProgramId mapreduce = appId.mr(AppWithProgramsUsingGuava.NoOpMR.NAME); startProgram(Id.Program.fromEntityId(mapreduce)); waitForRuns(1, mapreduce, ProgramRunStatus.FAILED); ProgramId workflow = appId.workflow(AppWithProgramsUsingGuava.NoOpWorkflow.NAME); startProgram(Id.Program.fromEntityId(workflow)); waitForRuns(1, workflow, ProgramRunStatus.FAILED); appId.workflow(AppWithProgramsUsingGuava.NoOpWorkflow.NAME); startProgram(Id.Program.fromEntityId(workflow), ImmutableMap.of("fail.in.workflow.initialize", "true")); waitForRuns(1, workflow, ProgramRunStatus.FAILED);
/** * Get the schedule id from the schedule spec */ private Set<ScheduleId> getSchedulesInApp(ApplicationId appId, Map<String, ? extends ScheduleCreationSpec> scheduleSpecs) { Set<ScheduleId> result = new HashSet<>(); for (String programName : scheduleSpecs.keySet()) { result.add(appId.schedule(programName)); } return result; }
@Override @SuppressWarnings("deprecation") public void perform(Arguments arguments, PrintStream output) throws Exception { String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\."); ApplicationId appId = cliConfig.getCurrentNamespace().app(programIdParts[0]); int instances; switch (elementType) { case WORKER: if (programIdParts.length < 2) { throw new CommandInputError(this); } String workerId = programIdParts[1]; ProgramId worker = appId.worker(workerId); instances = programClient.getWorkerInstances(worker); break; case SERVICE: if (programIdParts.length < 2) { throw new CommandInputError(this); } String serviceName = programIdParts[1]; instances = programClient.getServiceInstances(appId.service(serviceName)); break; default: // TODO: remove this throw new IllegalArgumentException("Unrecognized program element type for scaling: " + elementType); } output.println(instances); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { ApplicationId appId = parseApplicationId(arguments); appClient.delete(appId); output.printf("Successfully deleted application '%s.%s'\n", appId.getEntityName(), appId.getVersion()); }