use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class DataPipelineTest method testUpgradePipelinesWithNoChangeInPluginRange.
/* Tests upgrade for a deployed application with a plugin using plugin range.
1. Deploy an application with older application artifact (1.0.0) and filter plugin version with range
[1.0.0-2.0.0) to make sure latest version of plugin should be included in it.
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. Upgrade the older deployed application.
4. Verify that after upgrading, application artifact uses latest version in its config.
But plugin range is not updated as latest version of plugin is still included in the range.
*/
@Test
public void testUpgradePipelinesWithNoChangeInPluginRange() throws Exception {
ArtifactSelectorConfig currentArtifactSelector = new ArtifactSelectorConfig(ArtifactScope.USER.name(), "test-plugins", "[1.0.0,2.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 consider snapshot enabled to consider highest version of plugin available which is
// 1.1.1-SNAPSHOT.
appManager.upgrade(Collections.emptySet(), true);
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"));
// The filter stage is not changed as latest plugin is in the range.
Assert.assertEquals(oldStageMap.get("filter"), newStageMap.get("filter"));
// Verify that after upgrade, application upgrades artifact version to latest version available.
Assert.assertEquals(upgradedAppDetail.getArtifact().getVersion(), UPGRADE_APP_ARTIFACT_ID_3_SNAPSHOT.getVersion());
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class DataPipelineTest method testUpgradePipelinesWithPluginRange.
/* Tests upgrade for a deployed application with a plugin using plugin range.
1. Deploy an application with older application artifact (1.0.0) and older filter plugin version with range
[1.0.0-1.0.5).
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. Upgrade the older deployed application.
4. Verify that after upgrading, application artifact and filter plugin artifact is upgraded to use latest version
in its config. Also verify that plugin version range for filter stage is changed to use newest version of plugin.
*/
@Test
public void testUpgradePipelinesWithPluginRange() throws Exception {
ArtifactSelectorConfig currentArtifactSelector = new ArtifactSelectorConfig(ArtifactScope.USER.name(), "test-plugins", "[1.0.0,1.0.5)");
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.
appManager.upgrade();
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(upgradedAppDetail.getArtifact().getVersion(), UPGRADE_APP_ARTIFACT_ID_2.getVersion());
// Check if the filter stage, for which version range should be upgraded to include latest plugin version in SYSTEM
// scope.
ETLPlugin upgradedPlugin = newStageMap.get("filter").getPlugin();
Assert.assertEquals(upgradedPlugin.getArtifactConfig().getVersion(), "[1.0.0,1.1.0]");
Assert.assertEquals(ArtifactScope.valueOf(upgradedPlugin.getArtifactConfig().getScope().toUpperCase()), ArtifactScope.SYSTEM);
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class AppFabricServiceMainTest method testAppFabricService.
@Test
public void testAppFabricService() throws Exception {
// Query the system services endpoint
URL url = getRouterBaseURI().resolve("/v3/system/services").toURL();
HttpResponse response = HttpRequests.execute(HttpRequest.get(url).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// Deploy an app
LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
Location deploymentJar = AppJarHelper.createDeploymentJar(locationFactory, AllProgramsApp.class);
URI baseURI = getRouterBaseURI().resolve("/v3/namespaces/default/");
url = baseURI.resolve("apps").toURL();
HttpRequestConfig requestConfig = new HttpRequestConfig(0, 0, false);
response = HttpRequests.execute(HttpRequest.post(url).withBody((ContentProvider<? extends InputStream>) deploymentJar::getInputStream).addHeader("X-Archive-Name", AllProgramsApp.class.getSimpleName() + "-1.0-SNAPSHOT.jar").build(), requestConfig);
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// Get the application
url = baseURI.resolve("apps/" + AllProgramsApp.NAME).toURL();
response = HttpRequests.execute(HttpRequest.get(url).build(), requestConfig);
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
ApplicationDetail appDetail = new Gson().fromJson(response.getResponseBodyAsString(), ApplicationDetail.class);
// Do some basic validation only.
Assert.assertEquals(AllProgramsApp.NAME, appDetail.getName());
Assert.assertTrue(appDetail.getPrograms().stream().filter(r -> r.getType() == ProgramType.WORKFLOW).anyMatch(r -> AllProgramsApp.NoOpWorkflow.NAME.equals(r.getName())));
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
the class ApplicationClient method get.
/**
* Get details about the specified application.
*
* @param appId the id of the application to get
* @return details about the specified application
* @throws ApplicationNotFoundException if the application with the given ID was not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public ApplicationDetail get(ApplicationId appId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion());
HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveNamespacedURLV3(appId.getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(appId);
}
return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject();
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by caskdata.
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)));
}
Aggregations