Search in sources :

Example 41 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class RemoveMetadataPropertyCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    String property = arguments.get("property");
    client.removeProperty(entity, property);
    output.println("Successfully removed metadata property");
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId)

Example 42 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class AddMetadataPropertiesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    Map<String, String> properties = parseMap(arguments.get("properties"), "<properties>");
    client.addProperties(entity, properties);
    output.println("Successfully added metadata properties");
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId)

Example 43 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class GetMetadataCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    String scope = arguments.getOptional(ArgumentName.METADATA_SCOPE.toString());
    Set<MetadataRecord> metadata = scope == null ? client.getMetadata(entity) : client.getMetadata(entity, MetadataScope.valueOf(scope.toUpperCase()));
    Table table = Table.builder().setHeader("entity", "tags", "properties", "scope").setRows(Iterables.transform(metadata, new Function<MetadataRecord, List<String>>() {

        @Nullable
        @Override
        public List<String> apply(MetadataRecord record) {
            return Lists.newArrayList(record.getEntityId().toString(), Joiner.on("\n").join(record.getTags()), Joiner.on("\n").withKeyValueSeparator(":").join(record.getProperties()), record.getScope().name());
        }
    })).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) Table(co.cask.cdap.cli.util.table.Table) List(java.util.List) MetadataRecord(co.cask.cdap.common.metadata.MetadataRecord) Nullable(javax.annotation.Nullable)

Example 44 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class RemoveMetadataPropertiesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    client.removeProperties(entity);
    output.println("Successfully removed metadata properties");
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId)

Example 45 with EntityId

use of co.cask.cdap.proto.id.EntityId in project cdap by caskdata.

the class DatasetServiceClient method getInstance.

@Nullable
public DatasetMeta getInstance(String instanceName, @Nullable Iterable<? extends EntityId> owners) throws DatasetManagementException {
    String query = "";
    if (owners != null) {
        Set<String> ownerParams = Sets.newHashSet();
        for (EntityId owner : owners) {
            ownerParams.add("owner=" + owner.toString());
        }
        query = ownerParams.isEmpty() ? "" : "?" + Joiner.on("&").join(ownerParams);
    }
    HttpResponse response = doGet("datasets/" + instanceName + query);
    if (HttpResponseStatus.NOT_FOUND.code() == response.getResponseCode()) {
        return null;
    }
    if (HttpResponseStatus.FORBIDDEN.code() == response.getResponseCode()) {
        throw new DatasetManagementException(String.format("Failed to get dataset instance %s, details: %s", instanceName, response), new UnauthorizedException(response.getResponseBodyAsString()));
    }
    if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
        throw new DatasetManagementException(String.format("Cannot retrieve dataset instance %s info, details: %s", instanceName, response));
    }
    return GSON.fromJson(response.getResponseBodyAsString(), DatasetMeta.class);
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) HttpResponse(co.cask.common.http.HttpResponse) Nullable(javax.annotation.Nullable)

Aggregations

EntityId (co.cask.cdap.proto.id.EntityId)62 Principal (co.cask.cdap.proto.security.Principal)21 EnumSet (java.util.EnumSet)18 HashSet (java.util.HashSet)18 Set (java.util.Set)18 PartitionedFileSet (co.cask.cdap.api.dataset.lib.PartitionedFileSet)17 ImmutableSet (com.google.common.collect.ImmutableSet)17 Test (org.junit.Test)17 Action (co.cask.cdap.proto.security.Action)14 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)13 DatasetId (co.cask.cdap.proto.id.DatasetId)12 ProgramId (co.cask.cdap.proto.id.ProgramId)11 ApplicationManager (co.cask.cdap.test.ApplicationManager)11 ApplicationId (co.cask.cdap.proto.id.ApplicationId)10 StreamId (co.cask.cdap.proto.id.StreamId)9 NamespaceId (co.cask.cdap.proto.id.NamespaceId)8 PrivilegedAction (java.security.PrivilegedAction)8 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)7 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)7 Authorizer (co.cask.cdap.security.spi.authorization.Authorizer)7