use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class LoadArtifactCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
File artifactFile = resolver.resolvePathToFile(arguments.get(ArgumentName.LOCAL_FILE_PATH.toString()));
String name = arguments.getOptional(ArgumentName.ARTIFACT_NAME.toString());
String version = arguments.getOptional(ArgumentName.ARTIFACT_VERSION.toString());
ArtifactId artifactId;
if (name == null && version != null) {
throw new IllegalArgumentException("If a version is specified, name must also be specified.");
} else if (name != null && version == null) {
throw new IllegalArgumentException("If a name is specified, a version must also be specified.");
} else if (name == null) {
artifactId = new ArtifactId(cliConfig.getCurrentNamespace().getNamespace(), artifactFile.getName());
} else {
artifactId = cliConfig.getCurrentNamespace().artifact(name, version);
}
String configPath = arguments.getOptional(ArgumentName.ARTIFACT_CONFIG_FILE.toString());
NamespaceId namespace = artifactId.getParent();
if (configPath == null) {
artifactClient.add(namespace, artifactId.getEntityName(), Files.newInputStreamSupplier(artifactFile), artifactId.getVersion());
} else {
File configFile = resolver.resolvePathToFile(configPath);
ArtifactConfig artifactConfig = configReader.read(Id.Namespace.fromEntityId(namespace), configFile);
artifactClient.add(namespace, artifactId.getEntityName(), Files.newInputStreamSupplier(artifactFile), artifactId.getVersion(), artifactConfig.getParents(), artifactConfig.getPlugins());
Map<String, String> properties = artifactConfig.getProperties();
if (properties != null && !properties.isEmpty()) {
artifactClient.writeProperties(artifactId, properties);
}
}
output.printf("Successfully added artifact with name '%s'\n", artifactId.getEntityName());
}
use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class GetArtifactPropertiesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
ArtifactId artifactId = cliConfig.getCurrentNamespace().artifact(artifactName, artifactVersion);
String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
ArtifactInfo info;
if (scopeStr == null) {
info = artifactClient.getArtifactInfo(artifactId);
} else {
ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
info = artifactClient.getArtifactInfo(artifactId, scope);
}
List<Map.Entry<String, String>> rows = new ArrayList<>(info.getProperties().size());
rows.addAll(info.getProperties().entrySet());
Table table = Table.builder().setHeader("key", "value").setRows(rows, new RowMaker<Map.Entry<String, String>>() {
@Override
public List<String> makeRow(Map.Entry<String, String> entry) {
List<String> columns = new ArrayList<>(2);
columns.add(entry.getKey());
columns.add(entry.getValue());
return columns;
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ListArtifactPluginTypesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
ArtifactId artifactId = cliConfig.getCurrentNamespace().artifact(artifactName, artifactVersion);
List<String> types;
String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
if (scopeStr == null) {
types = artifactClient.getPluginTypes(artifactId);
} else {
types = artifactClient.getPluginTypes(artifactId, ArtifactScope.valueOf(scopeStr.toUpperCase()));
}
Table table = Table.builder().setHeader("plugin type").setRows(types, new RowMaker<String>() {
@Override
public List<?> makeRow(String object) {
return Lists.newArrayList(object);
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ArtifactHttpHandler method getProperty.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties/{property}")
public void getProperty(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("property") String key, @QueryParam("scope") @DefaultValue("user") String scope) throws Exception {
NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope);
ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
try {
ArtifactDetail detail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId));
responder.sendString(HttpResponseStatus.OK, detail.getMeta().getProperties().get(key));
} catch (IOException e) {
LOG.error("Exception reading property for artifact {}.", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading properties for artifact.");
}
}
use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactProperties.
@POST
@Path("/namespaces/{namespace-id}/artifactproperties")
public void getArtifactProperties(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
NamespaceId namespace = validateAndGetNamespace(namespaceId);
List<ArtifactPropertiesRequest> propertyRequests;
try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) {
propertyRequests = GSON.fromJson(reader, BATCH_ARTIFACT_PROPERTIES_REQUEST);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Unable to parse request: " + e.getMessage(), e);
}
List<ArtifactSummaryProperties> result = new ArrayList<>(propertyRequests.size());
for (ArtifactPropertiesRequest propertiesRequest : propertyRequests) {
NamespaceId requestNamespace = propertiesRequest.getScope() == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : namespace;
ArtifactId artifactId = validateAndGetArtifactId(requestNamespace, propertiesRequest.getName(), propertiesRequest.getVersion());
ArtifactDetail artifactDetail;
try {
artifactDetail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId));
} catch (ArtifactNotFoundException e) {
continue;
}
Map<String, String> properties = artifactDetail.getMeta().getProperties();
Map<String, String> filteredProperties = new HashMap<>(propertiesRequest.getProperties().size());
for (String propertyKey : propertiesRequest.getProperties()) {
if (properties.containsKey(propertyKey)) {
filteredProperties.put(propertyKey, properties.get(propertyKey));
}
}
result.add(new ArtifactSummaryProperties(propertiesRequest.getName(), propertiesRequest.getVersion(), propertiesRequest.getScope(), filteredProperties));
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result, BATCH_ARTIFACT_PROPERTIES_RESPONSE));
}
Aggregations