Search in sources :

Example 71 with Location

use of org.apache.twill.filesystem.Location in project cdap by caskdata.

the class LocalApplicationManagerTest method testInvalidConfigPipeline.

@Test(expected = ExecutionException.class)
public void testInvalidConfigPipeline() throws Exception {
    Location deployedJar = AppJarHelper.createDeploymentJar(lf, ConfigTestApp.class);
    ArtifactId artifactId = new ArtifactId("configtest", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
    ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar);
    AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, ConfigTestApp.class.getName(), "BadApp", null, GSON.toJson("invalid"));
    AppFabricTestHelper.getLocalManager().deploy(info).get();
}
Also used : ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) AppDeploymentInfo(co.cask.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ArtifactDescriptor(co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor) ConfigTestApp(co.cask.cdap.ConfigTestApp) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 72 with Location

use of org.apache.twill.filesystem.Location in project cdap by caskdata.

the class LocalApplicationManagerTest method testValidConfigPipeline.

@Test
public void testValidConfigPipeline() throws Exception {
    Location deployedJar = AppJarHelper.createDeploymentJar(lf, ConfigTestApp.class);
    ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("myStream", "myTable");
    ArtifactId artifactId = new ArtifactId("configtest", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
    ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar);
    AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, ConfigTestApp.class.getName(), "MyApp", null, GSON.toJson(config));
    AppFabricTestHelper.getLocalManager().deploy(info).get();
}
Also used : ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) AppDeploymentInfo(co.cask.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ArtifactDescriptor(co.cask.cdap.internal.app.runtime.artifact.ArtifactDescriptor) ConfigTestApp(co.cask.cdap.ConfigTestApp) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 73 with Location

use of org.apache.twill.filesystem.Location in project cdap by caskdata.

the class StorageProviderNamespaceAdminTest method test.

@Test
public void test() throws Exception {
    NamespaceId myspace = new NamespaceId("myspace");
    NamespaceMeta myspaceMeta = new NamespaceMeta.Builder().setName(myspace.getNamespace()).build();
    // the create/delete will look up meta so store that too
    namespaceStore.create(myspaceMeta);
    storageProviderNamespaceAdmin.create(myspaceMeta);
    Location namespaceLocation = namespacedLocationFactory.get(myspace);
    Assert.assertTrue(namespaceLocation.exists());
    storageProviderNamespaceAdmin.delete(myspace);
    Assert.assertFalse(namespaceLocation.exists());
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 74 with Location

use of org.apache.twill.filesystem.Location in project cdap by caskdata.

the class ArtifactInspectorTest method inspectAppsAndPlugins.

@Test
public void inspectAppsAndPlugins() throws Exception {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(ManifestFields.EXPORT_PACKAGE, InspectionApp.class.getPackage().getName());
    File appFile = createJar(InspectionApp.class, new File(TMP_FOLDER.newFolder(), "InspectionApp-1.0.0.jar"), manifest);
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "InspectionApp", "1.0.0");
    Location artifactLocation = Locations.toLocation(appFile);
    try (CloseableClassLoader artifactClassLoader = classLoaderFactory.createClassLoader(artifactLocation, new EntityImpersonator(artifactId.toEntityId(), new DefaultImpersonator(CConfiguration.create(), null)))) {
        ArtifactClasses classes = artifactInspector.inspectArtifact(artifactId, appFile, artifactClassLoader);
        // check app classes
        Set<ApplicationClass> expectedApps = ImmutableSet.of(new ApplicationClass(InspectionApp.class.getName(), "", new ReflectionSchemaGenerator(false).generate(InspectionApp.AConfig.class)));
        Assert.assertEquals(expectedApps, classes.getApps());
        // check plugin classes
        PluginClass expectedPlugin = new PluginClass(InspectionApp.PLUGIN_TYPE, InspectionApp.PLUGIN_NAME, InspectionApp.PLUGIN_DESCRIPTION, InspectionApp.AppPlugin.class.getName(), "pluginConf", ImmutableMap.of("y", new PluginPropertyField("y", "", "double", true, true), "isSomething", new PluginPropertyField("isSomething", "", "boolean", true, false)));
        Assert.assertEquals(ImmutableSet.of(expectedPlugin), classes.getPlugins());
    }
}
Also used : EntityImpersonator(co.cask.cdap.security.impersonation.EntityImpersonator) ApplicationClass(co.cask.cdap.api.artifact.ApplicationClass) CloseableClassLoader(co.cask.cdap.api.artifact.CloseableClassLoader) Manifest(java.util.jar.Manifest) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) DefaultImpersonator(co.cask.cdap.security.impersonation.DefaultImpersonator) PluginPropertyField(co.cask.cdap.api.plugin.PluginPropertyField) ArtifactClasses(co.cask.cdap.api.artifact.ArtifactClasses) Id(co.cask.cdap.proto.Id) PluginClass(co.cask.cdap.api.plugin.PluginClass) File(java.io.File) Location(org.apache.twill.filesystem.Location) InspectionApp(co.cask.cdap.internal.app.runtime.artifact.app.inspection.InspectionApp) Test(org.junit.Test)

Example 75 with Location

use of org.apache.twill.filesystem.Location in project cdap by caskdata.

the class NamespaceHttpHandlerTest method testDeleteDatasetsOnly.

@Test
public void testDeleteDatasetsOnly() throws Exception {
    CConfiguration cConf = getInjector().getInstance(CConfiguration.class);
    // test deleting non-existent namespace
    assertResponseCode(200, createNamespace(NAME));
    assertResponseCode(200, getNamespace(NAME));
    NamespacedLocationFactory namespacedLocationFactory = getInjector().getInstance(NamespacedLocationFactory.class);
    Location nsLocation = namespacedLocationFactory.get(new NamespaceId(NAME));
    Assert.assertTrue(nsLocation.exists());
    DatasetFramework dsFramework = getInjector().getInstance(DatasetFramework.class);
    deploy(AppWithServices.class, Constants.Gateway.API_VERSION_3_TOKEN, NAME);
    deploy(AppWithDataset.class, Constants.Gateway.API_VERSION_3_TOKEN, NAME);
    DatasetId myDataset = new DatasetId(NAME, "myds");
    Assert.assertTrue(dsFramework.hasInstance(myDataset));
    Id.Program program = Id.Program.from(NAME_ID, "AppWithServices", ProgramType.SERVICE, "NoOpService");
    startProgram(program);
    boolean resetEnabled = cConf.getBoolean(Constants.Dangerous.UNRECOVERABLE_RESET);
    cConf.setBoolean(Constants.Dangerous.UNRECOVERABLE_RESET, false);
    // because reset is not enabled
    assertResponseCode(403, deleteNamespaceData(NAME));
    Assert.assertTrue(nsLocation.exists());
    cConf.setBoolean(Constants.Dangerous.UNRECOVERABLE_RESET, resetEnabled);
    // because service is running
    assertResponseCode(409, deleteNamespaceData(NAME));
    Assert.assertTrue(nsLocation.exists());
    stopProgram(program);
    assertResponseCode(200, deleteNamespaceData(NAME));
    Assert.assertTrue(nsLocation.exists());
    Assert.assertTrue(getAppList(NAME).size() == 2);
    Assert.assertTrue(getAppDetails(NAME, "AppWithServices").get("name").getAsString().equals("AppWithServices"));
    Assert.assertTrue(getAppDetails(NAME, AppWithDataset.class.getSimpleName()).get("name").getAsString().equals(AppWithDataset.class.getSimpleName()));
    assertResponseCode(200, getNamespace(NAME));
    Assert.assertFalse(dsFramework.hasInstance(myDataset));
    assertResponseCode(200, deleteNamespace(NAME));
    assertResponseCode(404, getNamespace(NAME));
}
Also used : DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) NamespaceId(co.cask.cdap.proto.id.NamespaceId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) StreamId(co.cask.cdap.proto.id.StreamId) DatasetId(co.cask.cdap.proto.id.DatasetId) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Location(org.apache.twill.filesystem.Location) DatasetId(co.cask.cdap.proto.id.DatasetId) AppWithDataset(co.cask.cdap.AppWithDataset) AppForUnrecoverableResetTest(co.cask.cdap.AppForUnrecoverableResetTest) Test(org.junit.Test)

Aggregations

Location (org.apache.twill.filesystem.Location)246 Test (org.junit.Test)104 IOException (java.io.IOException)57 File (java.io.File)39 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)29 LocationFactory (org.apache.twill.filesystem.LocationFactory)29 FileSet (co.cask.cdap.api.dataset.lib.FileSet)28 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)27 PartitionedFileSet (co.cask.cdap.api.dataset.lib.PartitionedFileSet)23 CConfiguration (co.cask.cdap.common.conf.CConfiguration)19 NamespaceId (co.cask.cdap.proto.id.NamespaceId)19 Manifest (java.util.jar.Manifest)18 HashMap (java.util.HashMap)17 StreamId (co.cask.cdap.proto.id.StreamId)16 OutputStream (java.io.OutputStream)15 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)13 TimePartitionedFileSet (co.cask.cdap.api.dataset.lib.TimePartitionedFileSet)11 StreamConfig (co.cask.cdap.data2.transaction.stream.StreamConfig)10 ArrayList (java.util.ArrayList)9 StreamAdmin (co.cask.cdap.data2.transaction.stream.StreamAdmin)8