use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class TestFrameworkTestRun method testAppVersionsCreation.
@Test
public void testAppVersionsCreation() throws Exception {
ArtifactId artifactId = new ArtifactId(NamespaceId.DEFAULT.getNamespace(), "cfg-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, ConfigTestApp.class);
ApplicationId appId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "AppV1", "version1");
AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("tD1", "tV1"));
ApplicationManager appManager = deployApplication(appId, createRequest);
ServiceManager serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME);
serviceManager.start();
serviceManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
URL serviceURL = serviceManager.getServiceURL();
Gson gson = new Gson();
Assert.assertEquals("tV1", gson.fromJson(callServiceGet(serviceURL, "ping"), String.class));
serviceManager.stop();
serviceManager.waitForStopped(10, TimeUnit.SECONDS);
appId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "AppV1", "version2");
createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("tD2", "tV2"));
appManager = deployApplication(appId, createRequest);
serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME);
serviceManager.start();
serviceManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
serviceURL = serviceManager.getServiceURL();
Assert.assertEquals("tV2", gson.fromJson(callServiceGet(serviceURL, "ping"), String.class));
serviceManager.stop();
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class TestFrameworkTestRun method testAppWithPlugin.
@Test
public void testAppWithPlugin() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("app-with-plugin", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, AppWithPlugin.class);
ArtifactId pluginArtifactId = NamespaceId.DEFAULT.artifact("test-plugin", "1.0.0-SNAPSHOT");
addPluginArtifact(pluginArtifactId, artifactId, ToStringPlugin.class);
ApplicationId appId = NamespaceId.DEFAULT.app("AppWithPlugin");
AppRequest createRequest = new AppRequest(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
ApplicationManager appManager = deployApplication(appId, createRequest);
final WorkerManager workerManager = appManager.getWorkerManager(AppWithPlugin.WORKER);
workerManager.start();
workerManager.waitForRun(ProgramRunStatus.COMPLETED, 10, TimeUnit.SECONDS);
final ServiceManager serviceManager = appManager.getServiceManager(AppWithPlugin.SERVICE);
serviceManager.start();
serviceManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
URL serviceURL = serviceManager.getServiceURL(5, TimeUnit.SECONDS);
callServiceGet(serviceURL, "dummy");
serviceManager.stop();
serviceManager.waitForStopped(10, TimeUnit.SECONDS);
WorkflowManager workflowManager = appManager.getWorkflowManager(AppWithPlugin.WORKFLOW);
workflowManager.start();
workflowManager.waitForRun(ProgramRunStatus.COMPLETED, 5, TimeUnit.MINUTES);
List<RunRecord> runRecords = workflowManager.getHistory();
Assert.assertNotEquals(ProgramRunStatus.FAILED, runRecords.get(0).getStatus());
DataSetManager<KeyValueTable> workflowTableManager = getDataset(AppWithPlugin.WORKFLOW_TABLE);
String value = Bytes.toString(workflowTableManager.get().read("val"));
Assert.assertEquals(AppWithPlugin.TEST, value);
Map<String, String> workflowTags = ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, NamespaceId.DEFAULT.getNamespace(), Constants.Metrics.Tag.APP, "AppWithPlugin", Constants.Metrics.Tag.WORKFLOW, AppWithPlugin.WORKFLOW, Constants.Metrics.Tag.RUN_ID, runRecords.get(0).getPid());
getMetricsManager().waitForTotalMetricCount(workflowTags, String.format("user.destroy.%s", AppWithPlugin.WORKFLOW), 1, 60, TimeUnit.SECONDS);
// Testing Spark Plugins. First send some data to fileset for the Spark program to process
DataSetManager<FileSet> fileSetManager = getDataset(AppWithPlugin.SPARK_INPUT);
FileSet fileSet = fileSetManager.get();
try (PrintStream out = new PrintStream(fileSet.getLocation("input").append("file.txt").getOutputStream(), true, "UTF-8")) {
for (int i = 0; i < 5; i++) {
out.println("Message " + i);
}
}
Map<String, String> sparkArgs = new HashMap<>();
FileSetArguments.setInputPath(sparkArgs, "input");
SparkManager sparkManager = appManager.getSparkManager(AppWithPlugin.SPARK).start(sparkArgs);
sparkManager.waitForRun(ProgramRunStatus.COMPLETED, 2, TimeUnit.MINUTES);
// Verify the Spark result.
DataSetManager<Table> dataSetManager = getDataset(AppWithPlugin.SPARK_TABLE);
Table table = dataSetManager.get();
try (Scanner scanner = table.scan(null, null)) {
for (int i = 0; i < 5; i++) {
Row row = scanner.next();
Assert.assertNotNull(row);
String expected = "Message " + i + " " + AppWithPlugin.TEST;
Assert.assertEquals(expected, Bytes.toString(row.getRow()));
Assert.assertEquals(expected, Bytes.toString(row.get(expected)));
}
// There shouldn't be any more rows in the table.
Assert.assertNull(scanner.next());
}
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class TestFrameworkTestRun method testAppFromArtifact.
@Test
public void testAppFromArtifact() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("cfg-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, ConfigTestApp.class);
ApplicationId appId = NamespaceId.DEFAULT.app("AppFromArtifact");
AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("testStream", "testDataset"));
ApplicationManager appManager = deployApplication(appId, createRequest);
testAppConfig(appId.getApplication(), appManager, createRequest.getConfig());
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class RemotePluginConfigurer method addPlugin.
@Override
protected Plugin addPlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) throws PluginNotExistsException {
validateExistingPlugin(pluginId);
// plugin
if (!localPlugins.containsKey(pluginId)) {
return super.addPlugin(pluginType, pluginName, pluginId, properties, selector);
}
Plugin existingPlugin = localPlugins.get(pluginId);
File existingPluginLocation = new File(localPluginDir, Artifacts.getFileName(existingPlugin.getArtifactId()));
// need to regenerate this plugin to ensure the plugin has updated properties with macro resolved, also
// register it to plugin instantiator
io.cdap.cdap.api.artifact.ArtifactId artifactId = existingPlugin.getArtifactId();
String namespace = artifactId.getScope().equals(ArtifactScope.SYSTEM) ? NamespaceId.SYSTEM.getNamespace() : pluginNamespaceId.getNamespace();
Location pluginLocation = Locations.toLocation(existingPluginLocation);
SortedMap<io.cdap.cdap.api.artifact.ArtifactId, PluginClass> selectedPlugin = new TreeMap<>();
selectedPlugin.put(artifactId, existingPlugin.getPluginClass());
selector.select(selectedPlugin);
Plugin plugin = FindPluginHelper.getPlugin(existingPlugin.getParents(), Maps.immutableEntry(new ArtifactDescriptor(namespace, artifactId, pluginLocation), existingPlugin.getPluginClass()), properties, pluginInstantiator);
plugins.put(pluginId, new PluginWithLocation(plugin, pluginLocation));
return plugin;
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by cdapio.
the class AppLifecycleHttpHandlerTest method testDeployVersionedAndNonVersionedApp.
@Test
public void testDeployVersionedAndNonVersionedApp() throws Exception {
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "configapp", "1.0.0");
addAppArtifact(artifactId, ConfigTestApp.class);
ApplicationId appId = new ApplicationId(Id.Namespace.DEFAULT.getId(), "cfgAppWithVersion", "1.0.0");
ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("abc", "def");
AppRequest<ConfigTestApp.ConfigClass> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
Assert.assertEquals(200, deploy(appId, request).getResponseCode());
// Cannot update the app created by versioned API with versionId not ending with "-SNAPSHOT"
Assert.assertEquals(409, deploy(appId, request).getResponseCode());
Assert.assertEquals(404, getAppResponse(Id.Namespace.DEFAULT.getId(), appId.getApplication(), "non_existing_version").getResponseCode());
Assert.assertEquals(404, getAppResponse(Id.Namespace.DEFAULT.getId(), appId.getApplication()).getResponseCode());
// Deploy app with default versionId by non-versioned API
Id.Application appIdDefault = Id.Application.from(Id.Namespace.DEFAULT, appId.getApplication());
ConfigTestApp.ConfigClass configDefault = new ConfigTestApp.ConfigClass("uvw", "xyz");
AppRequest<ConfigTestApp.ConfigClass> requestDefault = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), configDefault);
Assert.assertEquals(200, deploy(appIdDefault, requestDefault).getResponseCode());
// Deploy app with versionId "version_2" by versioned API
ApplicationId appIdV2 = new ApplicationId(appId.getNamespace(), appId.getApplication(), "2.0.0");
ConfigTestApp.ConfigClass configV2 = new ConfigTestApp.ConfigClass("ghi", "jkl");
AppRequest<ConfigTestApp.ConfigClass> requestV2 = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), configV2);
Assert.assertEquals(200, deploy(appIdV2, requestV2).getResponseCode());
Set<String> versions = ImmutableSet.of("-SNAPSHOT", "2.0.0", "1.0.0");
Assert.assertEquals(versions, getAppVersions(appId.getNamespace(), appId.getApplication()));
List<JsonObject> appList = getAppList(appId.getNamespace());
Set<String> receivedVersions = new HashSet<>();
for (JsonObject appRecord : appList) {
receivedVersions.add(appRecord.getAsJsonPrimitive("version").getAsString());
}
Assert.assertEquals(versions, receivedVersions);
JsonObject appDetails = getAppDetails(appId.getNamespace(), appId.getApplication(), appId.getVersion());
Assert.assertEquals(GSON.toJson(config), appDetails.get("configuration").getAsString());
Assert.assertEquals(appId.getVersion(), appDetails.get("appVersion").getAsString());
// Get app info for the app with default versionId by versioned API
JsonObject appDetailsDefault = getAppDetails(appId.getNamespace(), appId.getApplication(), ApplicationId.DEFAULT_VERSION);
Assert.assertEquals(GSON.toJson(configDefault), appDetailsDefault.get("configuration").getAsString());
Assert.assertEquals(ApplicationId.DEFAULT_VERSION, appDetailsDefault.get("appVersion").getAsString());
// Get app info for the app with versionId "version_2" by versioned API
JsonObject appDetailsV2 = getAppDetails(appId.getNamespace(), appId.getApplication(), appIdV2.getVersion());
Assert.assertEquals(GSON.toJson(configV2), appDetailsV2.get("configuration").getAsString());
// Update app with default versionId by versioned API
ConfigTestApp.ConfigClass configDefault2 = new ConfigTestApp.ConfigClass("mno", "pqr");
AppRequest<ConfigTestApp.ConfigClass> requestDefault2 = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), configDefault2);
Assert.assertEquals(200, deploy(appIdDefault.toEntityId(), requestDefault2).getResponseCode());
JsonObject appDetailsDefault2 = getAppDetails(appIdDefault.getNamespaceId(), appIdDefault.getId());
Assert.assertEquals(GSON.toJson(configDefault2), appDetailsDefault2.get("configuration").getAsString());
// Get updated app info for the app with default versionId by versioned API
JsonObject appDetailsDefault2WithVersion = getAppDetails(appIdDefault.getNamespaceId(), appIdDefault.getId(), ApplicationId.DEFAULT_VERSION);
Assert.assertEquals(GSON.toJson(configDefault2), appDetailsDefault2WithVersion.get("configuration").getAsString());
Assert.assertEquals(ApplicationId.DEFAULT_VERSION, appDetailsDefault.get("appVersion").getAsString());
deleteApp(appId, 200);
deleteApp(appIdDefault, 200);
deleteApp(appIdV2, 200);
}
Aggregations