Search in sources :

Example 21 with ProgramId

use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.

the class SetProgramInstancesCommand method perform.

@Override
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 numInstances = arguments.getInt(ArgumentName.NUM_INSTANCES.toString());
    switch(elementType) {
        case WORKER:
            if (programIdParts.length < 2) {
                throw new CommandInputError(this);
            }
            String workerName = programIdParts[1];
            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:
            if (programIdParts.length < 2) {
                throw new CommandInputError(this);
            }
            String serviceName = programIdParts[1];
            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:
            // TODO: remove this
            throw new IllegalArgumentException("Unrecognized program element type for scaling: " + elementType);
    }
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ServiceId(io.cdap.cdap.proto.id.ServiceId)

Example 22 with ProgramId

use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.

the class SetProgramRuntimeArgsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    ProgramId programId = parseProgramId(arguments, elementType);
    String appName = programId.getApplication();
    String appVersion = programId.getVersion();
    String programName = programId.getProgram();
    String runtimeArgsString = arguments.get(ArgumentName.RUNTIME_ARGS.toString());
    Map<String, String> runtimeArgs = ArgumentParser.parseMap(runtimeArgsString, ArgumentName.RUNTIME_ARGS.toString());
    programClient.setRuntimeArgs(programId, runtimeArgs);
    output.printf("Successfully set runtime args of %s '%s' of application '%s.%s' to '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString);
}
Also used : ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 23 with ProgramId

use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.

the class StartProgramCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    ProgramId programId = parseProgramId(arguments, elementType);
    String appName = programId.getApplication();
    String appVersion = programId.getVersion();
    String programName = programId.getProgram();
    String runtimeArgsString = arguments.getOptional(ArgumentName.RUNTIME_ARGS.toString(), "");
    if (runtimeArgsString == null || runtimeArgsString.isEmpty()) {
        // run with stored runtime args
        programClient.start(programId, isDebug, null);
        runtimeArgsString = SPACE_EQUALS_JOINER.join(programClient.getRuntimeArgs(programId));
        output.printf("Successfully started %s '%s' of application '%s.%s' with stored runtime arguments '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString);
    } else {
        // run with user-provided runtime args
        Map<String, String> runtimeArgs = ArgumentParser.parseMap(runtimeArgsString, ArgumentName.RUNTIME_ARGS.toString());
        programClient.start(programId, isDebug, runtimeArgs);
        output.printf("Successfully started %s '%s' of application '%s.%s' with provided runtime arguments '%s'\n", elementType.getName(), programName, appName, appVersion, runtimeArgsString);
    }
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 24 with ProgramId

use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.

the class LogHttpHandlerTest method testFilterWithEmptyResult.

@Test
public void testFilterWithEmptyResult() throws Exception {
    String appId = "testTemplate1";
    String entityType = "workflows";
    String entityId = "testWorkflow1";
    String namespace = NamespaceId.DEFAULT.getEntityName();
    ProgramId programId = new NamespaceId(namespace).app(appId).program(ProgramType.valueOfCategoryName(entityType), entityId);
    RunRecord runRecord = mockLogReader.getRunRecord(programId);
    String logsUrl = String.format("apps/%s/%s/%s/runs/%s/logs?format=json&filter=MDC:asdf=nothing", appId, entityType, entityId, runRecord.getPid());
    HttpResponse response = doGet(getVersionedAPIPath(logsUrl, namespace));
    verifyLogs(response, entityId, "json", true, true, true, 0, 0);
}
Also used : RunRecord(io.cdap.cdap.proto.RunRecord) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 25 with ProgramId

use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.

the class LogHttpHandlerTest method testNativeMethodField.

// Verify the Json returned for logs has isNativeMethod set correctly
@Test
public void testNativeMethodField() throws Exception {
    ProgramId programId = new NamespaceId(MockLogReader.TEST_NAMESPACE).app("testTemplate1").program(ProgramType.valueOfCategoryName("workflows"), "testWorkflow1");
    RunRecord runRecord = mockLogReader.getRunRecord(programId);
    String logsUrl = String.format("apps/%s/%s/%s/runs/%s/logs/next?format=json", "testTemplate1", "workflows", "testWorkflow1", runRecord.getPid());
    HttpResponse response = doGet(getVersionedAPIPath(logsUrl, MockLogReader.TEST_NAMESPACE));
    Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    List<LogDataOffset> logDataOffsetList = GSON.fromJson(response.getResponseBodyAsString(), LIST_LOGDATA_OFFSET_TYPE);
    Assert.assertEquals(logDataOffsetList.size(), 15);
    Assert.assertTrue(logDataOffsetList.get(0).getLog().getNativeMethod());
    Assert.assertFalse(logDataOffsetList.get(1).getLog().getNativeMethod());
    Assert.assertFalse(logDataOffsetList.get(2).getLog().getNativeMethod());
}
Also used : RunRecord(io.cdap.cdap.proto.RunRecord) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Aggregations

ProgramId (io.cdap.cdap.proto.id.ProgramId)562 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)277 Test (org.junit.Test)268 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)164 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)130 RunId (org.apache.twill.api.RunId)118 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)110 ProgramType (io.cdap.cdap.proto.ProgramType)108 HashMap (java.util.HashMap)88 HashSet (java.util.HashSet)78 ArrayList (java.util.ArrayList)76 Id (io.cdap.cdap.common.id.Id)74 IOException (java.io.IOException)74 File (java.io.File)70 RunRecord (io.cdap.cdap.proto.RunRecord)68 Path (javax.ws.rs.Path)68 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)66 NotFoundException (io.cdap.cdap.common.NotFoundException)66 Map (java.util.Map)64 Set (java.util.Set)62