use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class ApplicationLifecycleServiceTest method testScanApplicationsWithFailingPredicate.
@Test
public void testScanApplicationsWithFailingPredicate() throws Exception {
createNamespace("ns1");
createNamespace("ns2");
createNamespace("ns3");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns1");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns2");
deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, "ns3");
List<ApplicationDetail> appDetails = new ArrayList<>();
applicationLifecycleService.scanApplications(new NamespaceId("ns1"), ImmutableSet.of("name1"), "version1", d -> appDetails.add(d));
Assert.assertEquals(appDetails.size(), 0);
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
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 cdapio.
the class ApplicationLifecycleService method createAppDetailsArchive.
/**
* Creates a ZIP archive that contains the {@link ApplicationDetail} for all applications. The archive created will
* contain a directory entry for each of the namespace. Inside each namespace directory, it contains the
* application detail json, the application name as the file name, with {@code ".json"} as the file extension.
* <p/>
* This method requires instance admin permission.
*
* @param zipOut the {@link ZipOutputStream} for writing out the application details
*/
public void createAppDetailsArchive(ZipOutputStream zipOut) throws Exception {
accessEnforcer.enforce(new InstanceId(cConf.get(Constants.INSTANCE_NAME)), authenticationContext.getPrincipal(), StandardPermission.GET);
Set<NamespaceId> namespaces = new HashSet<>();
JsonWriter jsonWriter = new JsonWriter(new OutputStreamWriter(zipOut, StandardCharsets.UTF_8));
store.scanApplications(batchSize, (appId, appSpec) -> {
// Skip the SYSTEM namespace apps
if (NamespaceId.SYSTEM.equals(appId.getParent())) {
return;
}
try {
ApplicationDetail applicationDetail = enforceApplicationDetailAccess(appId, ApplicationDetail.fromSpec(appSpec, null));
// Add a directory for the namespace
if (namespaces.add(appId.getParent())) {
ZipEntry entry = new ZipEntry(appId.getNamespace() + "/");
zipOut.putNextEntry(entry);
zipOut.closeEntry();
}
ZipEntry entry = new ZipEntry(appId.getNamespace() + "/" + appId.getApplication() + ".json");
zipOut.putNextEntry(entry);
GSON.toJson(applicationDetail, ApplicationDetail.class, jsonWriter);
jsonWriter.flush();
zipOut.closeEntry();
} catch (IOException | AccessException e) {
throw new RuntimeException("Failed to add zip entry for application " + appId, e);
}
});
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class ApplicationLifecycleService method getAppDetails.
/**
* Gets details for a set of given applications.
*
* @param appIds the set of application id to get details
* @return a {@link Map} from the application id to the corresponding detail. There will be no entry for applications
* that don't exist.
* @throws Exception if failed to get details.
*/
public Map<ApplicationId, ApplicationDetail> getAppDetails(Collection<ApplicationId> appIds) throws Exception {
Set<? extends EntityId> visibleIds = accessEnforcer.isVisible(new HashSet<>(appIds), authenticationContext.getPrincipal());
Set<ApplicationId> filterIds = appIds.stream().filter(visibleIds::contains).collect(Collectors.toSet());
Map<ApplicationId, ApplicationSpecification> appSpecs = store.getApplications(filterIds);
Map<ApplicationId, String> principals = ownerAdmin.getOwnerPrincipals(filterIds);
Map<ApplicationId, ApplicationDetail> result = new HashMap<>();
for (Map.Entry<ApplicationId, ApplicationSpecification> entry : appSpecs.entrySet()) {
ApplicationId appId = entry.getKey();
result.put(appId, enforceApplicationDetailAccess(appId, ApplicationDetail.fromSpec(entry.getValue(), principals.get(appId))));
}
return result;
}
use of io.cdap.cdap.proto.ApplicationDetail in project cdap by cdapio.
the class ApplicationDetailFetcherTest method testGetAllApplications.
@Test
public void testGetAllApplications() throws Exception {
ApplicationDetailFetcher fetcher = getApplicationDetailFetcher(fetcherType);
String namespace = TEST_NAMESPACE1;
List<ApplicationDetail> appDetailList = Collections.emptyList();
ApplicationDetail appDetail = null;
// No applications have been deployed
appDetailList = fetcher.list(namespace);
Assert.assertEquals(Collections.emptyList(), appDetailList);
// Deploy the application
deploy(AllProgramsApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespace);
// Get and validate the application
appDetailList = fetcher.list(namespace);
Assert.assertEquals(1, appDetailList.size());
appDetail = appDetailList.get(0);
assertAllProgramAppDetail(appDetail);
// Deploy another application
deploy(AppWithSchedule.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespace);
// Get and validate the application
appDetailList = fetcher.list(namespace);
Assert.assertEquals(2, appDetailList.size());
Assert.assertEquals(AllProgramsApp.NAME, appDetailList.get(0).getName());
Assert.assertEquals(AllProgramsApp.DESC, appDetailList.get(0).getDescription());
Assert.assertEquals(AppWithSchedule.NAME, appDetailList.get(1).getName());
Assert.assertEquals(AppWithSchedule.DESC, appDetailList.get(1).getDescription());
// Delete the application
Assert.assertEquals(200, doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, namespace)).getResponseCode());
}
Aggregations