Search in sources :

Example 21 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class DefaultStore method updateFlowletInstancesInAppSpec.

private static ApplicationSpecification updateFlowletInstancesInAppSpec(ApplicationSpecification appSpec, ProgramId id, String flowletId, int count) {
    FlowSpecification flowSpec = getFlowSpecOrFail(id, appSpec);
    FlowletDefinition flowletDef = getFlowletDefinitionOrFail(flowSpec, flowletId, id);
    FlowletDefinition adjustedFlowletDef = new FlowletDefinition(flowletDef, count);
    return replaceFlowletInAppSpec(appSpec, id, flowSpec, adjustedFlowletDef);
}
Also used : FlowletDefinition(co.cask.cdap.api.flow.FlowletDefinition) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ForwardingFlowSpecification(co.cask.cdap.internal.app.ForwardingFlowSpecification)

Example 22 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class DefaultStore method getFlowletInstances.

@Override
public int getFlowletInstances(ProgramId id, String flowletId) {
    return Transactionals.execute(transactional, context -> {
        ApplicationSpecification appSpec = getAppSpecOrFail(getAppMetadataStore(context), id);
        FlowSpecification flowSpec = getFlowSpecOrFail(id, appSpec);
        FlowletDefinition flowletDef = getFlowletDefinitionOrFail(flowSpec, flowletId, id);
        return flowletDef.getInstances();
    });
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ForwardingApplicationSpecification(co.cask.cdap.internal.app.ForwardingApplicationSpecification) FlowletDefinition(co.cask.cdap.api.flow.FlowletDefinition) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ForwardingFlowSpecification(co.cask.cdap.internal.app.ForwardingFlowSpecification)

Example 23 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class ProgramLifecycleService method setFlowletInstances.

private void setFlowletInstances(ProgramId programId, String flowletId, int instances) throws ExecutionException, InterruptedException, BadRequestException {
    int oldInstances = store.getFlowletInstances(programId, flowletId);
    if (oldInstances != instances) {
        FlowSpecification flowSpec = store.setFlowletInstances(programId, flowletId, instances);
        ProgramRuntimeService.RuntimeInfo runtimeInfo = findRuntimeInfo(programId);
        if (runtimeInfo != null) {
            runtimeInfo.getController().command(ProgramOptionConstants.INSTANCES, ImmutableMap.of("flowlet", flowletId, "newInstances", String.valueOf(instances), "oldFlowSpec", GSON.toJson(flowSpec, FlowSpecification.class))).get();
        }
    }
}
Also used : FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) RuntimeInfo(co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo) ProgramRuntimeService(co.cask.cdap.app.runtime.ProgramRuntimeService)

Example 24 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class DefaultStoreTest method testLoadingProgram.

@Test
public void testLoadingProgram() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new ToyApp());
    ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
    store.addApplication(appId, appSpec);
    ProgramDescriptor descriptor = store.loadProgram(appId.flow("ToyFlow"));
    Assert.assertNotNull(descriptor);
    FlowSpecification flowSpec = descriptor.getSpecification();
    Assert.assertEquals("ToyFlow", flowSpec.getName());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ToyApp(co.cask.cdap.ToyApp) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 25 with FlowSpecification

use of co.cask.cdap.api.flow.FlowSpecification in project cdap by caskdata.

the class FlowVerificationTest method testValidFlow.

@Test
public void testValidFlow() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    FlowVerification flowSpec = new FlowVerification();
    for (Map.Entry<String, FlowSpecification> entry : newSpec.getFlows().entrySet()) {
        VerifyResult result = flowSpec.verify(new ApplicationId("test", newSpec.getName()), entry.getValue());
        Assert.assertTrue(result.getStatus() == VerifyResult.Status.SUCCESS);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WebCrawlApp(co.cask.cdap.WebCrawlApp) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Map(java.util.Map) Test(org.junit.Test)

Aggregations

FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)25 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)15 FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)7 ApplicationId (co.cask.cdap.proto.id.ApplicationId)7 ProgramType (co.cask.cdap.proto.ProgramType)5 Test (org.junit.Test)4 VerifyResult (co.cask.cdap.app.verification.VerifyResult)3 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)3 ForwardingFlowSpecification (co.cask.cdap.internal.app.ForwardingFlowSpecification)3 ProgramId (co.cask.cdap.proto.id.ProgramId)3 WebCrawlApp (co.cask.cdap.WebCrawlApp)2 MapReduceSpecification (co.cask.cdap.api.mapreduce.MapReduceSpecification)2 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)2 SparkSpecification (co.cask.cdap.api.spark.SparkSpecification)2 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)2 ProgramController (co.cask.cdap.app.runtime.ProgramController)2 NotFoundException (co.cask.cdap.common.NotFoundException)2 QueueName (co.cask.cdap.common.queue.QueueName)2 ForwardingApplicationSpecification (co.cask.cdap.internal.app.ForwardingApplicationSpecification)2 SimpleQueueSpecificationGenerator (co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator)2