use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class CapabilityApplier method shouldDeployApp.
// Returns true if capability applier should try to deploy this application. 2 conditions when it returns true:
// 1. Either the application is not deployed before.
// 2. If application is deployed before then the app artifact of the deployed application is not the latest one
// available.
private boolean shouldDeployApp(ApplicationId applicationId, SystemApplication application) throws Exception {
ApplicationDetail currAppDetail;
try {
currAppDetail = applicationLifecycleService.getAppDetail(applicationId);
} catch (ApplicationNotFoundException exception) {
return true;
}
// Compare if the app artifact version of currently deployed application with highest version of app artifact
// available. If it's not same, capability applier should redeploy application.
ArtifactSummary summary = application.getArtifact();
NamespaceId artifactNamespace = ArtifactScope.SYSTEM.equals(summary.getScope()) ? NamespaceId.SYSTEM : applicationId.getParent();
ArtifactRange range = new ArtifactRange(artifactNamespace.getNamespace(), summary.getName(), ArtifactVersionRange.parse(summary.getVersion()));
// this method will not throw ArtifactNotFoundException, if no artifacts in the range, we are expecting an empty
// collection returned.
List<ArtifactDetail> artifactDetail = artifactRepository.getArtifactDetails(range, 1, ArtifactSortOrder.DESC);
if (artifactDetail.isEmpty()) {
throw new ArtifactNotFoundException(range.getNamespace(), range.getName());
}
ArtifactId latestArtifactId = artifactDetail.get(0).getDescriptor().getArtifactId();
// same artifact. If same means no need to deploy the application again.
return !currAppDetail.getArtifact().getVersion().equals(latestArtifactId.getVersion().getVersion());
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class DataPipelineTest method testSimpleUpgradePipelinesWithArtifactScope.
/* Tests upgrade for a deployed application. Also tests artifact scope parameter for only considering artifacts in
a given scope.
1. Deploy an application with older application artifact (1.0.0) and older filter plugin version (1.0.0).
2. Add new versions of application artifacts (0.0.9, 1.1.0, 1.2.0) and filter plugin artifacts (1.0.5, 1.1.0) in
SYSTEM scope (in test class setup).
3. Also deploy a snapshot version of plugin artifact 1.0.8 in USER scope.
3. Upgrade the older deployed application with artifact scope set to USER for upgrade.
4. Verify that after upgrading, application artifact and filter plugin artifact is upgraded to use latest version
in its config and it uses snapshot plugin version with 1.0.8 from USER scope.
*/
@Test
public void testSimpleUpgradePipelinesWithArtifactScope() throws Exception {
ArtifactSelectorConfig currentArtifactSelector = new ArtifactSelectorConfig(ArtifactScope.USER.name(), "test-plugins", "1.0.0");
Engine engine = Engine.MAPREDUCE;
String sourceName = "testSource" + engine.name();
String sinkName = "testSink" + engine.name();
ETLBatchConfig etlConfig = ETLBatchConfig.builder().setEngine(engine).addStage(new ETLStage("source", MockSource.getPlugin(sourceName))).addStage(new ETLStage("filter", PluggableFilterTransform.getPlugin(ValueFilter.NAME, ValueFilter.getProperties("${field}", "${value}"), currentArtifactSelector))).addStage(new ETLStage("sink", MockSink.getPlugin(sinkName))).addConnection("source", "filter").addConnection("filter", "sink").build();
AppRequest<ETLBatchConfig> appRequest = new AppRequest<>(APP_ARTIFACT, etlConfig);
ApplicationId appId = NamespaceId.DEFAULT.app("sparkProgramTest");
// Deploy app with artifact version 1.0.0.
ApplicationManager appManager = deployApplication(appId, appRequest);
ApplicationDetail oldAppDetail = getAppDetail(appId);
ETLBatchConfig oldBatchConfig = GSON.fromJson(oldAppDetail.getConfiguration(), ETLBatchConfig.class);
Map<String, ETLStage> oldStageMap = oldBatchConfig.getStages().stream().collect(Collectors.toMap(ETLStage::getName, e -> e));
// Upgrade application with artifact scope as USER.
appManager.upgrade(Collections.singleton(ArtifactScope.USER.toString()), false);
ApplicationDetail upgradedAppDetail = getAppDetail(appId);
ETLBatchConfig newBatchConfig = GSON.fromJson(upgradedAppDetail.getConfiguration(), ETLBatchConfig.class);
Map<String, ETLStage> newStageMap = newBatchConfig.getStages().stream().collect(Collectors.toMap(ETLStage::getName, e -> e));
// Compare stages that should be same after upgrade.
Assert.assertEquals(oldStageMap.get("source"), newStageMap.get("source"));
Assert.assertEquals(oldStageMap.get("sink"), newStageMap.get("sink"));
// Verify that after upgrade, application upgrades artifact version to latest version available.
Assert.assertEquals(UPGRADE_APP_ARTIFACT_ID_2.getVersion(), upgradedAppDetail.getArtifact().getVersion());
// Check if the filter stage, for which version should be upgraded to desired version in SYSTEM scope.
ETLPlugin upgradedPlugin = newStageMap.get("filter").getPlugin();
Assert.assertEquals("1.0.8", upgradedPlugin.getArtifactConfig().getVersion());
Assert.assertEquals(ArtifactScope.valueOf(upgradedPlugin.getArtifactConfig().getScope().toUpperCase()), ArtifactScope.USER);
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class AppLifecycleHttpHandlerInternal method getAllAppDetails.
/**
* Get a list of {@link ApplicationDetail} for all applications in the given namespace
*
* @param request {@link HttpRequest}
* @param responder {@link HttpResponse}
* @param namespace the namespace to get all application details
* @throws Exception if namespace doesn't exists or failed to get all application details
*/
@GET
@Path("/apps")
public void getAllAppDetails(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception {
NamespaceId namespaceId = new NamespaceId(namespace);
if (!namespaceQueryAdmin.exists(namespaceId)) {
throw new NamespaceNotFoundException(namespaceId);
}
ScanApplicationsRequest scanApplicationsRequest = ScanApplicationsRequest.builder().setNamespaceId(namespaceId).build();
JsonWholeListResponder.respond(GSON, responder, jsonListResponder -> applicationLifecycleService.scanApplications(scanApplicationsRequest, d -> jsonListResponder.send(d)));
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class AppLifecycleHttpHandlerTest method testListAndGet.
@Test
public void testListAndGet() throws Exception {
// deploy without name to testnamespace1
deploy(AllProgramsApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
// deploy with name to testnamespace2
String ns2AppName = AllProgramsApp.NAME + "2";
Id.Namespace ns2 = Id.Namespace.from(TEST_NAMESPACE2);
Id.Artifact ns2ArtifactId = Id.Artifact.from(ns2, AllProgramsApp.class.getSimpleName(), "1.0.0-SNAPSHOT");
HttpResponse response = addAppArtifact(ns2ArtifactId, AllProgramsApp.class);
Assert.assertEquals(200, response.getResponseCode());
Id.Application appId = Id.Application.from(ns2, ns2AppName);
response = deploy(appId, new AppRequest<>(ArtifactSummary.from(ns2ArtifactId.toArtifactId())));
Assert.assertEquals(200, response.getResponseCode());
// deploy with name and version to testnamespace2
ApplicationId app1 = new ApplicationId(TEST_NAMESPACE2, ns2AppName, VERSION1);
response = deploy(app1, new AppRequest<>(ArtifactSummary.from(ns2ArtifactId.toArtifactId())));
Assert.assertEquals(200, response.getResponseCode());
// verify testnamespace1 has 1 app
List<JsonObject> apps = getAppList(TEST_NAMESPACE1);
Assert.assertEquals(1, apps.size());
// verify testnamespace2 has 2 app
apps = getAppList(TEST_NAMESPACE2);
Assert.assertEquals(2, apps.size());
// get and verify app details in testnamespace1
JsonObject result = getAppDetails(TEST_NAMESPACE1, AllProgramsApp.NAME);
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
Assert.assertEquals(AllProgramsApp.NAME, result.get("name").getAsString());
Assert.assertEquals(AllProgramsApp.DESC, result.get("description").getAsString());
// Validate the datasets
JsonArray datasets = result.get("datasets").getAsJsonArray();
Assert.assertEquals(spec.getDatasets().size(), datasets.size());
Assert.assertTrue(StreamSupport.stream(datasets.spliterator(), false).map(JsonObject.class::cast).map(obj -> obj.get("name").getAsString()).allMatch(dataset -> spec.getDatasets().containsKey(dataset)));
// Validate the programs
JsonArray programs = result.get("programs").getAsJsonArray();
int totalPrograms = Arrays.stream(io.cdap.cdap.api.app.ProgramType.values()).mapToInt(type -> spec.getProgramsByType(type).size()).reduce(0, (l, r) -> l + r);
Assert.assertEquals(totalPrograms, programs.size());
Assert.assertTrue(StreamSupport.stream(programs.spliterator(), false).map(JsonObject.class::cast).allMatch(obj -> {
String type = obj.get("type").getAsString().toUpperCase();
io.cdap.cdap.api.app.ProgramType programType = io.cdap.cdap.api.app.ProgramType.valueOf(type);
return spec.getProgramsByType(programType).contains(obj.get("name").getAsString());
}));
// get and verify app details in testnamespace2
List<BatchApplicationDetail> appDetails = getAppDetails(TEST_NAMESPACE2, Arrays.asList(ImmutablePair.of(ns2AppName, null), ImmutablePair.of(ns2AppName, VERSION1)));
Assert.assertEquals(2, appDetails.size());
Assert.assertTrue(appDetails.stream().allMatch(d -> d.getStatusCode() == 200));
ApplicationDetail appDetail = appDetails.get(0).getDetail();
Assert.assertNotNull(appDetail);
Assert.assertEquals(ns2AppName, appDetail.getName());
Assert.assertEquals(ApplicationId.DEFAULT_VERSION, appDetail.getAppVersion());
appDetail = appDetails.get(1).getDetail();
Assert.assertNotNull(appDetail);
Assert.assertEquals(ns2AppName, appDetail.getName());
Assert.assertEquals(VERSION1, appDetail.getAppVersion());
// delete app in testnamespace1
response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
Assert.assertEquals(200, response.getResponseCode());
// delete app in testnamespace2
response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
Assert.assertEquals(200, response.getResponseCode());
deleteArtifact(ns2ArtifactId, 200);
// verify testnamespace2 has 0 app
apps = getAppList(TEST_NAMESPACE2);
Assert.assertEquals(0, apps.size());
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class ApplicationClientTestRun method testAll.
@Test
public void testAll() throws Exception {
ApplicationId app = NamespaceId.DEFAULT.app(FakeApp.NAME);
Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
// deploy app
LOG.info("Deploying app");
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, FakeApp.NAME, "1.0.0-SNAPSHOT"));
appClient.waitForDeployed(app, 30, TimeUnit.SECONDS);
Assert.assertEquals(1, appClient.list(NamespaceId.DEFAULT).size());
try {
// check program list
LOG.info("Checking program list for app");
Map<ProgramType, List<ProgramRecord>> programs = appClient.listProgramsByType(app);
verifyProgramNames(FakeApp.MAPREDUCES, programs.get(ProgramType.MAPREDUCE));
verifyProgramNames(FakeApp.WORKFLOWS, programs.get(ProgramType.WORKFLOW));
verifyProgramNames(FakeApp.SERVICES, programs.get(ProgramType.SERVICE));
verifyProgramNames(FakeApp.MAPREDUCES, appClient.listPrograms(app, ProgramType.MAPREDUCE));
verifyProgramNames(FakeApp.WORKFLOWS, appClient.listPrograms(app, ProgramType.WORKFLOW));
verifyProgramNames(FakeApp.SERVICES, appClient.listPrograms(app, ProgramType.SERVICE));
verifyProgramNames(FakeApp.MAPREDUCES, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.MAPREDUCE));
verifyProgramNames(FakeApp.WORKFLOWS, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.WORKFLOW));
verifyProgramNames(FakeApp.SERVICES, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.SERVICE));
verifyProgramRecords(FakeApp.ALL_PROGRAMS, appClient.listAllPrograms(NamespaceId.DEFAULT));
ApplicationDetail appDetail = appClient.get(app);
ArtifactSummary expected = new ArtifactSummary(FakeApp.NAME, "1.0.0-SNAPSHOT");
Assert.assertEquals(expected, appDetail.getArtifact());
} finally {
// delete app
LOG.info("Deleting app");
appClient.delete(app);
appClient.waitForDeleted(app, 30, TimeUnit.SECONDS);
Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
}
}
Aggregations