use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class HydratorTestBase method setupBatchArtifacts.
protected static void setupBatchArtifacts(ArtifactId artifactId, Class<?> appClass) throws Exception {
// add the app artifact
addAppArtifact(artifactId, appClass, BatchSource.class.getPackage().getName(), Action.class.getPackage().getName(), AutoJoiner.class.getPackage().getName(), JoinError.class.getPackage().getName(), Condition.class.getPackage().getName(), PipelineConfigurable.class.getPackage().getName(), AccessType.class.getPackage().getName(), InvalidStageException.class.getPackage().getName(), SQLEngine.class.getPackage().getName(), SQLDataset.class.getPackage().getName(), SQLPushRequest.class.getPackage().getName(), PushCapability.class.getPackage().getName(), SparkRecordCollection.class.getPackage().getName(), Connector.class.getPackage().getName(), "org.apache.avro.mapred", "org.apache.avro", "org.apache.avro.generic", "org.apache.avro.io");
batchMocksArtifactId = new ArtifactId(artifactId.getNamespace(), artifactId.getArtifact() + "-mocks", artifactId.getVersion());
// add plugins artifact
addPluginArtifact(batchMocksArtifactId, artifactId, BATCH_MOCK_PLUGINS, io.cdap.cdap.etl.mock.batch.MockSource.class, io.cdap.cdap.etl.mock.batch.MockSink.class, MockExternalSource.class, MockExternalSink.class, MockSQLEngine.class, MockSQLEngineWithCapabilities.class, MockSQLEngineWithStageSettings.class, DoubleTransform.class, AllErrorTransform.class, IdentityTransform.class, IntValueFilterTransform.class, StringValueFilterTransform.class, FieldCountAggregator.class, FieldsPrefixTransform.class, StringValueFilterCompute.class, NullFieldSplitterTransform.class, NullAlertTransform.class, FileMoveAction.class);
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class RemoteArtifactManager method getArtifactLocation.
@Override
protected Location getArtifactLocation(ArtifactInfo artifactInfo, @Nullable String artifactNamespace) throws IOException, UnauthorizedException {
String namespace;
if (ArtifactScope.SYSTEM.equals(artifactInfo.getScope())) {
namespace = NamespaceId.SYSTEM.getNamespace();
} else if (artifactNamespace != null) {
namespace = artifactNamespace;
} else {
namespace = namespaceId.getNamespace();
}
// If ArtifactLocalizerClient is set, use it to get the cached location of artifact.
if (artifactLocalizerClient != null) {
ArtifactId artifactId = new ArtifactId(namespace, artifactInfo.getName(), artifactInfo.getVersion());
try {
// artifact ClassLoader only.
return Locations.toLocation(artifactLocalizerClient.getUnpackedArtifactLocation(artifactId));
} catch (ArtifactNotFoundException e) {
throw new IOException(String.format("Artifact %s is not found", artifactId), e);
}
}
HttpRequest.Builder requestBuilder = remoteClientInternal.requestBuilder(HttpMethod.GET, String.format("namespaces/%s/artifacts/%s/versions/%s/location", namespace, artifactInfo.getName(), artifactInfo.getVersion()));
HttpResponse httpResponse = remoteClientInternal.execute(requestBuilder.build());
if (httpResponse.getResponseCode() == HttpResponseStatus.NOT_FOUND.code()) {
throw new IOException("Could not get artifact detail, endpoint not found");
}
if (httpResponse.getResponseCode() != 200) {
throw new IOException(String.format("Exception while getting artifacts list %s", httpResponse.getResponseBodyAsString()));
}
String path = httpResponse.getResponseBodyAsString();
Location location = Locations.getLocationFromAbsolutePath(locationFactory, path);
if (!location.exists()) {
throw new IOException(String.format("Artifact location does not exist %s for artifact %s version %s", path, artifactInfo.getName(), artifactInfo.getVersion()));
}
return location;
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testDeployWithExtraConfig.
@Test
public void testDeployWithExtraConfig() throws Exception {
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "extraConfig", "1.0.0-SNAPSHOT");
Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "ExtraConfigApp");
HttpResponse response = addAppArtifact(artifactId, AppWithNoServices.class);
Assert.assertEquals(200, response.getResponseCode());
response = deploy(appId, new AppRequest<>(ArtifactSummary.from(artifactId.toArtifactId()), new ExtraConfig()));
Assert.assertEquals(200, response.getResponseCode());
deleteApp(appId, 200);
deleteArtifact(artifactId, 200);
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testDeployUsingArtifact.
@Test
public void testDeployUsingArtifact() throws Exception {
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "configapp", "1.0.0");
addAppArtifact(artifactId, ConfigTestApp.class);
Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "cfgApp");
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());
JsonObject appDetails = getAppDetails(Id.Namespace.DEFAULT.getId(), appId.getId());
Assert.assertEquals(GSON.toJson(config), appDetails.get("configuration").getAsString());
Assert.assertEquals(200, doDelete(getVersionedAPIPath("apps/" + appId.getId(), appId.getNamespaceId())).getResponseCode());
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
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