Search in sources :

Example 6 with FlowletId

use of co.cask.cdap.proto.id.FlowletId in project cdap by caskdata.

the class GetProgramInstancesCommand method perform.

@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 FLOWLET:
            if (programIdParts.length < 3) {
                throw new CommandInputError(this);
            }
            String flowId = programIdParts[1];
            String flowletName = programIdParts[2];
            FlowletId flowlet = appId.flow(flowId).flowlet(flowletName);
            instances = programClient.getFlowletInstances(flowlet);
            break;
        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);
}
Also used : CommandInputError(co.cask.cdap.cli.exception.CommandInputError) FlowletId(co.cask.cdap.proto.id.FlowletId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId)

Example 7 with FlowletId

use of co.cask.cdap.proto.id.FlowletId in project cdap by caskdata.

the class LineageDatasetTest method testOneRelation.

@Test
public void testOneRelation() throws Exception {
    final LineageDataset lineageDataset = getLineageDataset("testOneRelation");
    Assert.assertNotNull(lineageDataset);
    TransactionExecutor txnl = dsFrameworkUtil.newInMemoryTransactionExecutor((TransactionAware) lineageDataset);
    final RunId runId = RunIds.generate(10000);
    final DatasetId datasetInstance = new DatasetId("default", "dataset1");
    final ProgramId program = new ProgramId("default", "app1", ProgramType.FLOW, "flow1");
    final FlowletId flowlet = program.flowlet("flowlet1");
    final ProgramRunId run = program.run(runId.getId());
    final long accessTimeMillis = System.currentTimeMillis();
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            lineageDataset.addAccess(run, datasetInstance, AccessType.READ, accessTimeMillis, flowlet);
        }
    });
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Relation expected = new Relation(datasetInstance, program, AccessType.READ, runId, ImmutableSet.of(flowlet));
            Set<Relation> relations = lineageDataset.getRelations(datasetInstance, 0, 100000, Predicates.<Relation>alwaysTrue());
            Assert.assertEquals(1, relations.size());
            Assert.assertEquals(expected, relations.iterator().next());
            Assert.assertEquals(toSet(program, datasetInstance), lineageDataset.getEntitiesForRun(run));
            Assert.assertEquals(ImmutableList.of(accessTimeMillis), lineageDataset.getAccessTimesForRun(run));
        }
    });
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TransactionExecutor(org.apache.tephra.TransactionExecutor) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) FlowletId(co.cask.cdap.proto.id.FlowletId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) RunId(org.apache.twill.api.RunId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Aggregations

FlowletId (co.cask.cdap.proto.id.FlowletId)7 ProgramId (co.cask.cdap.proto.id.ProgramId)6 ApplicationId (co.cask.cdap.proto.id.ApplicationId)5 Test (org.junit.Test)4 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)3 RunId (org.apache.twill.api.RunId)3 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)2 FakeApp (co.cask.cdap.client.app.FakeApp)2 DatasetId (co.cask.cdap.proto.id.DatasetId)2 StreamId (co.cask.cdap.proto.id.StreamId)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Set (java.util.Set)2 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)1 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)1 FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)1 Flowlet (co.cask.cdap.api.flow.flowlet.Flowlet)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 Node (co.cask.cdap.app.queue.QueueSpecificationGenerator.Node)1 NotFoundException (co.cask.cdap.common.NotFoundException)1