Search in sources :

Example 26 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class SparkTestRun method testScalaSparkCrossNSDataset.

@Test
public void testScalaSparkCrossNSDataset() throws Exception {
    // Deploy and create a dataset in namespace datasetSpaceForSpark
    NamespaceMeta inputDSNSMeta = new NamespaceMeta.Builder().setName("datasetSpaceForSpark").build();
    getNamespaceAdmin().create(inputDSNSMeta);
    deploy(inputDSNSMeta.getNamespaceId(), SparkAppUsingObjectStore.class);
    DataSetManager<ObjectStore<String>> keysManager = getDataset(inputDSNSMeta.getNamespaceId().dataset("keys"));
    prepareInputData(keysManager);
    Map<String, String> args = ImmutableMap.of(ScalaCharCountProgram.INPUT_DATASET_NAMESPACE(), inputDSNSMeta.getNamespaceId().getNamespace(), ScalaCharCountProgram.INPUT_DATASET_NAME(), "keys");
    ApplicationManager applicationManager = deploy(SparkAppUsingObjectStore.class);
    SparkManager sparkManager = applicationManager.getSparkManager(ScalaCharCountProgram.class.getSimpleName()).start(args);
    sparkManager.waitForRun(ProgramRunStatus.COMPLETED, 1, TimeUnit.MINUTES);
    DataSetManager<KeyValueTable> countManager = getDataset("count");
    checkOutputData(countManager);
}
Also used : ObjectStore(co.cask.cdap.api.dataset.lib.ObjectStore) SparkAppUsingObjectStore(co.cask.cdap.spark.app.SparkAppUsingObjectStore) ApplicationManager(co.cask.cdap.test.ApplicationManager) SparkManager(co.cask.cdap.test.SparkManager) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) Test(org.junit.Test)

Example 27 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class NamespaceHttpHandler method getNamespace.

@GET
@Path("/namespaces/{namespace-id}")
public void getNamespace(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    NamespaceMeta ns = namespaceAdmin.get(new NamespaceId(namespaceId));
    responder.sendJson(HttpResponseStatus.OK, ns);
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 28 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class NamespaceHttpHandler method create.

@PUT
@Path("/namespaces/{namespace-id}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void create(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    Id.Namespace namespace;
    try {
        namespace = Id.Namespace.from(namespaceId);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Namespace id can contain only alphanumeric characters or '_'.");
    }
    NamespaceMeta metadata = getNamespaceMeta(request);
    if (isReserved(namespaceId)) {
        throw new BadRequestException(String.format("Cannot create the namespace '%s'. '%s' is a reserved namespace.", namespaceId, namespaceId));
    }
    NamespaceMeta.Builder builder = metadata == null ? new NamespaceMeta.Builder() : new NamespaceMeta.Builder(metadata);
    builder.setName(namespace);
    NamespaceMeta finalMetadata = builder.build();
    try {
        namespaceAdmin.create(finalMetadata);
        responder.sendString(HttpResponseStatus.OK, String.format("Namespace '%s' created successfully.", namespaceId));
    } catch (AlreadyExistsException e) {
        responder.sendString(HttpResponseStatus.OK, String.format("Namespace '%s' already exists.", namespaceId));
    }
}
Also used : AlreadyExistsException(co.cask.cdap.common.AlreadyExistsException) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) BadRequestException(co.cask.cdap.common.BadRequestException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 29 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class NamespaceHttpHandler method updateNamespaceProperties.

@PUT
@Path("/namespaces/{namespace-id}/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void updateNamespaceProperties(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    NamespaceMeta meta = getNamespaceMeta(request);
    namespaceAdmin.updateProperties(new NamespaceId(namespaceId), meta);
    responder.sendString(HttpResponseStatus.OK, String.format("Updated properties for namespace '%s'.", namespaceId));
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 30 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class UpgradeTool method upgrade.

private Set<ApplicationId> upgrade() throws Exception {
    Set<ApplicationId> upgraded = new HashSet<>();
    for (NamespaceMeta namespaceMeta : namespaceClient.list()) {
        NamespaceId namespace = new NamespaceId(namespaceMeta.getName());
        upgraded.addAll(upgrade(namespace));
    }
    return upgraded;
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) HashSet(java.util.HashSet)

Aggregations

NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)58 NamespaceId (co.cask.cdap.proto.id.NamespaceId)26 Test (org.junit.Test)22 IOException (java.io.IOException)12 Location (org.apache.twill.filesystem.Location)6 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)5 BadRequestException (co.cask.cdap.common.BadRequestException)5 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)5 ApplicationManager (co.cask.cdap.test.ApplicationManager)5 ExecutionException (java.util.concurrent.ExecutionException)5 NamespaceConfig (co.cask.cdap.proto.NamespaceConfig)4 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 RowMaker (co.cask.cdap.cli.util.RowMaker)3 Table (co.cask.cdap.cli.util.table.Table)3 NotFoundException (co.cask.cdap.common.NotFoundException)3 CConfiguration (co.cask.cdap.common.conf.CConfiguration)3 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)3 Id (co.cask.cdap.proto.Id)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3