Search in sources :

Example 6 with Config

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);
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) Config(io.cdap.cdap.api.Config) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ServiceId(io.cdap.cdap.proto.id.ServiceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) AppRequest(io.cdap.cdap.proto.artifact.AppRequest)

Example 7 with Config

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());
}
Also used : Config(io.cdap.cdap.api.Config) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Test(org.junit.Test)

Example 8 with Config

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;
}
Also used : PluginConfig(io.cdap.cdap.api.plugin.PluginConfig) Config(io.cdap.cdap.api.Config) Schema(io.cdap.cdap.api.data.schema.Schema) Attributes(java.util.jar.Attributes) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ZipException(java.util.zip.ZipException) Manifest(java.util.jar.Manifest) InvalidMetadataException(io.cdap.cdap.common.InvalidMetadataException) ZipException(java.util.zip.ZipException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) EOFException(java.io.EOFException) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) IOException(java.io.IOException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) Application(io.cdap.cdap.api.app.Application) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException)

Example 9 with Config

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());
    }
}
Also used : FakeApp(io.cdap.cdap.client.app.FakeApp) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) Config(io.cdap.cdap.api.Config) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord) Test(org.junit.Test)

Example 10 with Config

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);
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) Config(io.cdap.cdap.api.Config) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Before(org.junit.Before)

Aggregations

Config (io.cdap.cdap.api.Config)16 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)10 Test (org.junit.Test)10 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)8 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)8 ProgramId (io.cdap.cdap.proto.id.ProgramId)8 Id (io.cdap.cdap.common.id.Id)6 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)6 ProfileId (io.cdap.cdap.proto.id.ProfileId)6 ScheduleDetail (io.cdap.cdap.proto.ScheduleDetail)4 ScheduleId (io.cdap.cdap.proto.id.ScheduleId)4 HttpResponse (io.cdap.common.http.HttpResponse)4 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Iterables (com.google.common.collect.Iterables)2 Lists (com.google.common.collect.Lists)2 Service (com.google.common.util.concurrent.Service)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 TypeToken (com.google.gson.reflect.TypeToken)2