Search in sources :

Example 26 with ApplicationId

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

the class DefaultPreviewStoreTest method testPreviewInfo.

@Test
public void testPreviewInfo() throws IOException {
    // test non existing preview
    ApplicationId nonexist = new ApplicationId("ns1", "nonexist");
    Assert.assertNull(store.getProgramRunId(nonexist));
    Assert.assertNull(store.getPreviewStatus(nonexist));
    // test put and get
    ApplicationId applicationId = new ApplicationId("ns1", "app1");
    ProgramRunId runId = new ProgramRunId("ns1", "app1", ProgramType.WORKFLOW, "test", RunIds.generate().getId());
    PreviewStatus status = new PreviewStatus(PreviewStatus.Status.COMPLETED, System.currentTimeMillis(), null, 0L, System.currentTimeMillis());
    store.setProgramId(runId);
    store.setPreviewStatus(applicationId, status);
    Assert.assertEquals(runId, store.getProgramRunId(applicationId));
    Assert.assertEquals(status, store.getPreviewStatus(applicationId));
}
Also used : PreviewStatus(io.cdap.cdap.app.preview.PreviewStatus) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 27 with ApplicationId

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

the class BaseBatchCommand method readArgs.

/**
 * Reads arguments to get app id, program types, and list of input programs.
 */
protected Args<T> readArgs(Arguments arguments) throws ApplicationNotFoundException, UnauthenticatedException, IOException, UnauthorizedException {
    String appName = arguments.get(ArgumentName.APP.getName());
    ApplicationId appId = cliConfig.getCurrentNamespace().app(appName);
    Set<ProgramType> programTypes = getDefaultProgramTypes();
    if (arguments.hasArgument(ArgumentName.PROGRAM_TYPES.getName())) {
        programTypes.clear();
        String programTypesStr = arguments.get(ArgumentName.PROGRAM_TYPES.getName());
        for (String programTypeStr : Splitter.on(',').trimResults().split(programTypesStr)) {
            ProgramType programType = ProgramType.valueOf(programTypeStr.toUpperCase());
            programTypes.add(programType);
        }
    }
    List<T> programs = new ArrayList<>();
    Map<ProgramType, List<ProgramRecord>> appPrograms = appClient.listProgramsByType(appId);
    for (ProgramType programType : programTypes) {
        List<ProgramRecord> programRecords = appPrograms.get(programType);
        if (programRecords != null) {
            for (ProgramRecord programRecord : programRecords) {
                programs.add(createProgram(programRecord));
            }
        }
    }
    return new Args<>(appId, programTypes, programs);
}
Also used : ProgramRecord(io.cdap.cdap.proto.ProgramRecord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ProgramType(io.cdap.cdap.proto.ProgramType) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 28 with ApplicationId

use of io.cdap.cdap.proto.id.ApplicationId 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 29 with ApplicationId

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

the class ProgramExistenceVerifier method ensureExists.

@Override
public void ensureExists(ProgramId programId) throws ApplicationNotFoundException, ProgramNotFoundException {
    ApplicationId appId = programId.getParent();
    ApplicationSpecification appSpec = store.getApplication(appId);
    if (appSpec == null) {
        throw new ApplicationNotFoundException(appId);
    }
    ProgramType programType = programId.getType();
    Set<String> programNames = null;
    if (programType == ProgramType.MAPREDUCE && appSpec.getMapReduce() != null) {
        programNames = appSpec.getMapReduce().keySet();
    } else if (programType == ProgramType.WORKFLOW && appSpec.getWorkflows() != null) {
        programNames = appSpec.getWorkflows().keySet();
    } else if (programType == ProgramType.SERVICE && appSpec.getServices() != null) {
        programNames = appSpec.getServices().keySet();
    } else if (programType == ProgramType.SPARK && appSpec.getSpark() != null) {
        programNames = appSpec.getSpark().keySet();
    } else if (programType == ProgramType.WORKER && appSpec.getWorkers() != null) {
        programNames = appSpec.getWorkers().keySet();
    }
    if (programNames != null) {
        if (programNames.contains(programId.getProgram())) {
            // is valid.
            return;
        }
    }
    throw new ProgramNotFoundException(programId);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) ProgramType(io.cdap.cdap.proto.ProgramType) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException)

Example 30 with ApplicationId

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

the class LocalPreferencesFetcherInternal method get.

/**
 * Get preferences for the given identify
 */
public PreferencesDetail get(EntityId entityId, boolean resolved) {
    final PreferencesService service = preferencesService;
    PreferencesDetail detail = null;
    switch(entityId.getEntityType()) {
        case INSTANCE:
            detail = resolved ? service.getResolvedPreferences() : service.getPreferences();
            break;
        case NAMESPACE:
            NamespaceId namespaceId = (NamespaceId) entityId;
            detail = resolved ? service.getResolvedPreferences(namespaceId) : service.getPreferences(namespaceId);
            break;
        case APPLICATION:
            ApplicationId appId = (ApplicationId) entityId;
            detail = resolved ? service.getResolvedPreferences(appId) : service.getPreferences(appId);
            break;
        case PROGRAM:
            ProgramId programId = (ProgramId) entityId;
            detail = resolved ? service.getResolvedPreferences(programId) : service.getPreferences(programId);
            break;
        default:
            throw new UnsupportedOperationException(String.format("Preferences cannot be used on this entity type: %s", entityId.getEntityType()));
    }
    return detail;
}
Also used : PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) PreferencesService(io.cdap.cdap.config.PreferencesService)

Aggregations

ApplicationId (io.cdap.cdap.proto.id.ApplicationId)374 Test (org.junit.Test)191 ProgramId (io.cdap.cdap.proto.id.ProgramId)131 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)120 ApplicationManager (io.cdap.cdap.test.ApplicationManager)98 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)93 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)79 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)78 Table (io.cdap.cdap.api.dataset.table.Table)77 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)77 WorkflowManager (io.cdap.cdap.test.WorkflowManager)74 Schema (io.cdap.cdap.api.data.schema.Schema)72 ArrayList (java.util.ArrayList)64 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)62 HashSet (java.util.HashSet)60 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)52 HashMap (java.util.HashMap)49 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)44 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)44 Path (javax.ws.rs.Path)37