Search in sources :

Example 96 with ApplicationId

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

the class CapabilityManagementServiceTest method reset.

@After
public void reset() throws Exception {
    // Reset all relevant stores.
    for (ApplicationDetail appDetail : applicationLifecycleService.getApps(NamespaceId.SYSTEM)) {
        programLifecycleService.stopAll(new ApplicationId(NamespaceId.SYSTEM.getNamespace(), appDetail.getName(), appDetail.getAppVersion()));
    }
    for (ApplicationDetail appDetail : applicationLifecycleService.getApps(NamespaceId.DEFAULT)) {
        programLifecycleService.stopAll(new ApplicationId(NamespaceId.DEFAULT.getNamespace(), appDetail.getName(), appDetail.getAppVersion()));
    }
    applicationLifecycleService.removeAll(NamespaceId.SYSTEM);
    applicationLifecycleService.removeAll(NamespaceId.DEFAULT);
    artifactRepository.clear(NamespaceId.SYSTEM);
    artifactRepository.clear(NamespaceId.DEFAULT);
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) After(org.junit.After)

Example 97 with ApplicationId

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

the class CapabilityManagementServiceTest method testCapabilityRefreshWithNewArtifact.

@Test
public void testCapabilityRefreshWithNewArtifact() throws Exception {
    String externalConfigPath = tmpFolder.newFolder("capability-config-refresh-redeploy").getAbsolutePath();
    cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
    String appName = AllProgramsApp.NAME;
    String programName = AllProgramsApp.NoOpService.NAME;
    Class<AllProgramsApp> appClass = AllProgramsApp.class;
    String appVersion = "1.0.0";
    String namespace = NamespaceId.SYSTEM.getNamespace();
    // deploy the artifact with older version.
    String oldArtifactVersion = "1.0.0";
    deployTestArtifact(namespace, appName, oldArtifactVersion, appClass);
    ApplicationId applicationId = new ApplicationId(namespace, appName, appVersion);
    ProgramId programId = new ProgramId(applicationId, ProgramType.SERVICE, programName);
    // check that app is not available
    List<JsonObject> appList = getAppList(namespace);
    Assert.assertTrue(appList.isEmpty());
    // enable the capability
    CapabilityConfig config = getTestConfig(oldArtifactVersion);
    writeConfigAsFile(externalConfigPath, config.getCapability(), config);
    capabilityManagementService.runTask();
    // app should show up and program should have run
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    String capability = config.getCapability();
    capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
    // disable capability. Program should stop, status should be disabled and app should still be present.
    CapabilityConfig disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
    writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), disabledConfig);
    capabilityManagementService.runTask();
    assertProgramRuns(programId, ProgramRunStatus.KILLED, 1);
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 0);
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    String newArtifactVersion = "2.0.0";
    // deploy the new artifact.
    deployTestArtifact(namespace, appName, newArtifactVersion, appClass);
    // enable the capability again.
    config = getTestConfig(newArtifactVersion);
    writeConfigAsFile(externalConfigPath, config.getCapability(), config);
    capabilityManagementService.runTask();
    // app should show up with newer artifact and program should have run.
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // Verify that application is redeployed with newer artifact.
    Assert.assertEquals(newArtifactVersion, appList.get(0).get("artifact").getAsJsonObject().get("version").getAsString());
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    capability = config.getCapability();
    capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
    // disable capability again. Program should stop, status should be disabled and app should still be present.
    disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
    writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), disabledConfig);
    capabilityManagementService.runTask();
    assertProgramRuns(programId, ProgramRunStatus.KILLED, 1);
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 0);
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // delete capability. Program should stop, status should be disabled and app should still be present.
    new File(externalConfigPath, disabledConfig.getCapability()).delete();
    capabilityManagementService.runTask();
    Assert.assertTrue(capabilityStatusStore.getConfigs(Collections.singleton(capability)).isEmpty());
    appList = getAppList(namespace);
    Assert.assertTrue(appList.isEmpty());
}
Also used : JsonObject(com.google.gson.JsonObject) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) File(java.io.File) Test(org.junit.Test)

Example 98 with ApplicationId

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

the class CapabilityManagementServiceTest method testCapabilityManagement.

@Test
public void testCapabilityManagement() throws Exception {
    String appName = AllProgramsApp.NAME;
    String programName = AllProgramsApp.NoOpService.NAME;
    Class<AllProgramsApp> appClass = AllProgramsApp.class;
    String version = "1.0.0";
    String namespace = NamespaceId.SYSTEM.getNamespace();
    // deploy the artifact
    deployTestArtifact(namespace, appName, version, appClass);
    ApplicationId applicationId = new ApplicationId(namespace, appName, version);
    ProgramId programId = new ProgramId(applicationId, ProgramType.SERVICE, programName);
    String externalConfigPath = tmpFolder.newFolder("capability-config-test").getAbsolutePath();
    cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
    String fileName = "cap1.json";
    File testJson = new File(CapabilityManagementServiceTest.class.getResource(String.format("/%s", fileName)).getPath());
    Files.copy(testJson, new File(externalConfigPath, fileName));
    capabilityManagementService.runTask();
    List<JsonObject> appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    // remove the file and make sure it gets removed
    new File(externalConfigPath, fileName).delete();
    capabilityManagementService.runTask();
    Assert.assertTrue(getAppList(namespace).isEmpty());
    // insert a pending entry, this should get re-applied and enable the capability
    FileReader fileReader = new FileReader(testJson);
    CapabilityConfig capabilityConfig = GSON.fromJson(fileReader, CapabilityConfig.class);
    capabilityStatusStore.addOrUpdateCapabilityOperation("cap1", CapabilityAction.ENABLE, capabilityConfig);
    capabilityManagementService.runTask();
    capabilityStatusStore.checkAllEnabled(Collections.singleton("cap1"));
    Assert.assertEquals(0, capabilityStatusStore.getCapabilityRecords().values().stream().filter(capabilityRecord -> capabilityRecord.getCapabilityOperationRecord() != null).count());
    // pending task out of the way , on next run should be deleted
    capabilityManagementService.runTask();
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton("cap1"));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    // disable from delete and see if it is applied correctly
    CapabilityConfig disableConfig = new CapabilityConfig(capabilityConfig.getLabel(), CapabilityStatus.DISABLED, capabilityConfig.getCapability(), capabilityConfig.getApplications(), capabilityConfig.getPrograms(), capabilityConfig.getHubs());
    writeConfigAsFile(externalConfigPath, fileName, disableConfig);
    capabilityManagementService.runTask();
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton("cap1"));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    Assert.assertEquals(disableConfig, capabilityStatusStore.getConfigs(Collections.singleton("cap1")).get("cap1"));
    // enable again
    writeConfigAsFile(externalConfigPath, fileName, capabilityConfig);
    capabilityManagementService.runTask();
    capabilityStatusStore.checkAllEnabled(Collections.singleton("cap1"));
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    // cleanup
    new File(externalConfigPath, fileName).delete();
    capabilityManagementService.runTask();
}
Also used : JsonObject(com.google.gson.JsonObject) AllProgramsApp(io.cdap.cdap.AllProgramsApp) FileReader(java.io.FileReader) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) File(java.io.File) Test(org.junit.Test)

Example 99 with ApplicationId

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

the class CapabilityManagementServiceTest method testCapabilityRefreshWithSameArtifact.

@Test
public void testCapabilityRefreshWithSameArtifact() throws Exception {
    String externalConfigPath = tmpFolder.newFolder("capability-config-refresh-redeploy-same").getAbsolutePath();
    cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
    String appName = AllProgramsApp.NAME;
    String programName = AllProgramsApp.NoOpService.NAME;
    Class<AllProgramsApp> appClass = AllProgramsApp.class;
    String appVersion = "1.0.0";
    String namespace = NamespaceId.SYSTEM.getNamespace();
    // deploy the artifact with older version.
    String artifactVersion = "1.0.0";
    deployTestArtifact(namespace, appName, artifactVersion, appClass);
    ApplicationId applicationId = new ApplicationId(namespace, appName, appVersion);
    ProgramId programId = new ProgramId(applicationId, ProgramType.SERVICE, programName);
    // check that app is not available
    List<JsonObject> appList = getAppList(namespace);
    Assert.assertTrue(appList.isEmpty());
    // enable the capability
    CapabilityConfig config = getTestConfig(artifactVersion);
    writeConfigAsFile(externalConfigPath, config.getCapability(), config);
    capabilityManagementService.runTask();
    // app should show up and program should have run
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    String capability = config.getCapability();
    capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
    // disable capability. Program should stop, status should be disabled and app should still be present.
    CapabilityConfig disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
    writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), disabledConfig);
    capabilityManagementService.runTask();
    assertProgramRuns(programId, ProgramRunStatus.KILLED, 1);
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 0);
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // enable the capability again but with same artifact.
    config = getTestConfig(artifactVersion);
    writeConfigAsFile(externalConfigPath, config.getCapability(), config);
    capabilityManagementService.runTask();
    // app should show up with newer artifact and program should have run.
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // Verify that application is still same as before.
    Assert.assertEquals(artifactVersion, appList.get(0).get("artifact").getAsJsonObject().get("version").getAsString());
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    capability = config.getCapability();
    capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
    // disable capability again. Program should stop, status should be disabled and app should still be present.
    disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
    writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), disabledConfig);
    capabilityManagementService.runTask();
    assertProgramRuns(programId, ProgramRunStatus.KILLED, 1);
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 0);
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // delete capability. Program should stop, status should be disabled and app should still be present.
    new File(externalConfigPath, disabledConfig.getCapability()).delete();
    capabilityManagementService.runTask();
    Assert.assertTrue(capabilityStatusStore.getConfigs(Collections.singleton(capability)).isEmpty());
    appList = getAppList(namespace);
    Assert.assertTrue(appList.isEmpty());
}
Also used : JsonObject(com.google.gson.JsonObject) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) File(java.io.File) Test(org.junit.Test)

Example 100 with ApplicationId

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

the class ApplicationDetailFetcherTest method testGetApplicationNotFound.

@Test(expected = NotFoundException.class)
public void testGetApplicationNotFound() throws Exception {
    ApplicationDetailFetcher fetcher = getApplicationDetailFetcher(fetcherType);
    String namespace = TEST_NAMESPACE1;
    String appName = AllProgramsApp.NAME;
    ApplicationId appId = new ApplicationId(namespace, appName);
    fetcher.get(appId);
}
Also used : ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Aggregations

ApplicationId (io.cdap.cdap.proto.id.ApplicationId)789 Test (org.junit.Test)410 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)279 ProgramId (io.cdap.cdap.proto.id.ProgramId)263 ApplicationManager (io.cdap.cdap.test.ApplicationManager)225 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)223 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)196 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)180 Table (io.cdap.cdap.api.dataset.table.Table)178 WorkflowManager (io.cdap.cdap.test.WorkflowManager)169 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)154 Schema (io.cdap.cdap.api.data.schema.Schema)147 ArrayList (java.util.ArrayList)129 HashSet (java.util.HashSet)126 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)124 HashMap (java.util.HashMap)109 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)107 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)88 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)88 Path (javax.ws.rs.Path)75