use of io.cdap.cdap.api.Config in project cdap by cdapio.
the class ProgramLifecycleHttpHandlerTest method testHistory.
private void testHistory(Class<?> app, Id.Program program) throws Exception {
String namespace = program.getNamespaceId();
deploy(app, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespace);
verifyProgramHistory(program.toEntityId());
deleteApp(program.getApplication(), 200);
ApplicationId appId = new ApplicationId(namespace, program.getApplicationId(), VERSION1);
ProgramId programId = appId.program(program.getType(), program.getId());
Id.Artifact artifactId = Id.Artifact.from(program.getNamespace(), app.getSimpleName(), "1.0.0");
addAppArtifact(artifactId, app);
AppRequest<Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), null);
Assert.assertEquals(200, deploy(appId, request).getResponseCode());
verifyProgramHistory(programId);
deleteApp(appId, 200);
}
use of io.cdap.cdap.api.Config in project cdap by cdapio.
the class ScheduleFetcherTest method testGetSchedule.
@Test
public void testGetSchedule() throws Exception {
ScheduleFetcher fetcher = getScheduleFetcher(fetcherType);
String namespace = TEST_NAMESPACE1;
String appName = AppWithSchedule.NAME;
String schedule = AppWithSchedule.SCHEDULE;
// Deploy the application with just 1 schedule on the workflow.
Config appConfig = new AppWithSchedule.AppConfig(true, true, false);
deploy(AppWithSchedule.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespace, appConfig);
// Get and validate the schedule
ScheduleId scheduleId = new ScheduleId(namespace, appName, schedule);
ScheduleDetail scheduleDetail = fetcher.get(scheduleId);
Assert.assertEquals(schedule, scheduleDetail.getName());
// Delete the application
Assert.assertEquals(200, doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, namespace)).getResponseCode());
}
use of io.cdap.cdap.api.Config in project cdap by cdapio.
the class DefaultArtifactInspector method inspectApplications.
private ArtifactClasses.Builder inspectApplications(Id.Artifact artifactId, ArtifactClasses.Builder builder, Location artifactLocation, ClassLoader artifactClassLoader) throws IOException, InvalidArtifactException {
// right now we force users to include the application main class as an attribute in their manifest,
// which forces them to have a single application class.
// in the future, we may want to let users do this or maybe specify a list of classes or
// a package that will be searched for applications, to allow multiple applications in a single artifact.
String mainClassName;
try {
Manifest manifest = BundleJarUtil.getManifest(artifactLocation);
if (manifest == null) {
return builder;
}
Attributes manifestAttributes = manifest.getMainAttributes();
if (manifestAttributes == null) {
return builder;
}
mainClassName = manifestAttributes.getValue(ManifestFields.MAIN_CLASS);
} catch (ZipException e) {
throw new InvalidArtifactException(String.format("Couldn't unzip artifact %s, please check it is a valid jar file.", artifactId), e);
}
if (mainClassName == null) {
return builder;
}
try {
Class<?> mainClass = artifactClassLoader.loadClass(mainClassName);
if (!(Application.class.isAssignableFrom(mainClass))) {
// possible for 3rd party plugin artifacts to have the main class set
return builder;
}
Application app = (Application) mainClass.newInstance();
java.lang.reflect.Type configType;
// we can deserialize the config into that object. Otherwise it'll just be a Config
try {
configType = Artifacts.getConfigType(app.getClass());
} catch (Exception e) {
throw new InvalidArtifactException(String.format("Could not resolve config type for Application class %s in artifact %s. " + "The type must extend Config and cannot be parameterized.", mainClassName, artifactId));
}
Schema configSchema = configType == Config.class ? null : schemaGenerator.generate(configType);
builder.addApp(new ApplicationClass(mainClassName, "", configSchema, getArtifactRequirements(app.getClass())));
} catch (ClassNotFoundException e) {
throw new InvalidArtifactException(String.format("Could not find Application main class %s in artifact %s.", mainClassName, artifactId));
} catch (UnsupportedTypeException e) {
throw new InvalidArtifactException(String.format("Config for Application %s in artifact %s has an unsupported schema. " + "The type must extend Config and cannot be parameterized.", mainClassName, artifactId));
} catch (InstantiationException | IllegalAccessException e) {
throw new InvalidArtifactException(String.format("Could not instantiate Application class %s in artifact %s.", mainClassName, artifactId), e);
}
return builder;
}
use of io.cdap.cdap.api.Config in project cdap by caskdata.
the class ApplicationClientTestRun method testArtifactFilter.
@Test
public void testArtifactFilter() throws Exception {
ApplicationId appId1 = NamespaceId.DEFAULT.app(FakeApp.NAME);
ApplicationId appId2 = NamespaceId.DEFAULT.app("fake2");
ApplicationId appId3 = NamespaceId.DEFAULT.app("fake3");
try {
// app1 should use fake-1.0.0-SNAPSHOT
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "otherfake", "1.0.0-SNAPSHOT"));
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "fake", "0.1.0-SNAPSHOT"));
// app1 should end up with fake-1.0.0-SNAPSHOT
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "fake", "1.0.0-SNAPSHOT"));
// app2 should use fake-0.1.0-SNAPSHOT
appClient.deploy(appId2, new AppRequest<Config>(new ArtifactSummary("fake", "0.1.0-SNAPSHOT")));
// app3 should use otherfake-1.0.0-SNAPSHOT
appClient.deploy(appId3, new AppRequest<Config>(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT")));
appClient.waitForDeployed(appId1, 30, TimeUnit.SECONDS);
appClient.waitForDeployed(appId2, 30, TimeUnit.SECONDS);
appClient.waitForDeployed(appId3, 30, TimeUnit.SECONDS);
// check calls that should return nothing
// these don't match anything
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "ghost", null).isEmpty());
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, (String) null, "1.0.0").isEmpty());
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "ghost", "1.0.0").isEmpty());
// these match one but not the other
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "otherfake", "0.1.0-SNAPSHOT").isEmpty());
Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "fake", "1.0.0").isEmpty());
// check filter by name only
Set<ApplicationRecord> apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "fake", null));
Set<ApplicationRecord> expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
Assert.assertEquals(expected, apps);
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "otherfake", null));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""));
Assert.assertEquals(expected, apps);
// check filter by multiple names
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, ImmutableSet.of("fake", "otherfake"), null));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""), new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
Assert.assertEquals(expected, apps);
// check filter by version only
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, (String) null, "0.1.0-SNAPSHOT"));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
Assert.assertEquals(expected, apps);
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, (String) null, "1.0.0-SNAPSHOT"));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""));
Assert.assertEquals(expected, apps);
// check filter by both
apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "fake", "0.1.0-SNAPSHOT"));
expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
Assert.assertEquals(expected, apps);
} finally {
appClient.deleteAll(NamespaceId.DEFAULT);
appClient.waitForDeleted(appId1, 30, TimeUnit.SECONDS);
appClient.waitForDeleted(appId2, 30, TimeUnit.SECONDS);
appClient.waitForDeleted(appId3, 30, TimeUnit.SECONDS);
Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
}
}
use of io.cdap.cdap.api.Config in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method before.
@Before
public void before() throws Exception {
addAppArtifact(artifactId, AppWithDataset.class);
AppRequest<Config> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
appClient.deploy(application, appRequest);
// Ensure the system metadata has been processed
Tasks.waitFor(false, () -> getProperties(artifactId, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Tasks.waitFor(false, () -> getProperties(application, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Tasks.waitFor(false, () -> getProperties(pingService, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
}
Aggregations