use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ArtifactClient method listVersions.
/**
* Lists all versions of the given artifact in the given namespace.
*
* @param namespace the namespace to list artifact versions in
* @param artifactName the name of the artifact
* @param scope the scope of artifacts to get. If none is given, the scope defaults to the user scope
* @return list of {@link ArtifactSummary}
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the given artifact does not exist
*/
public List<ArtifactSummary> listVersions(NamespaceId namespace, String artifactName, @Nullable ArtifactScope scope) throws UnauthenticatedException, IOException, ArtifactNotFoundException, UnauthorizedException {
URL url = scope == null ? config.resolveNamespacedURLV3(namespace, String.format("artifacts/%s", artifactName)) : config.resolveNamespacedURLV3(namespace, String.format("artifacts/%s?scope=%s", artifactName, scope.name()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(namespace, artifactName);
}
return ObjectResponse.<List<ArtifactSummary>>fromJsonBody(response, ARTIFACT_SUMMARIES_TYPE).getResponseObject();
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class IntegrationTestBase method doClear.
private void doClear(NamespaceId namespace, boolean deleteNamespace) throws Exception {
// stop all programs in the namespace
getProgramClient().stopAll(namespace);
if (deleteNamespace) {
getNamespaceClient().delete(namespace);
return;
}
// delete all apps in the namespace
for (ApplicationRecord app : getApplicationClient().list(namespace)) {
getApplicationClient().delete(namespace.app(app.getName(), app.getAppVersion()));
}
// delete all dataset instances
for (DatasetSpecificationSummary datasetSpecSummary : getDatasetClient().list(namespace)) {
getDatasetClient().delete(namespace.dataset(datasetSpecSummary.getName()));
}
ArtifactClient artifactClient = new ArtifactClient(getClientConfig(), getRestClient());
for (ArtifactSummary artifactSummary : artifactClient.list(namespace, ArtifactScope.USER)) {
artifactClient.delete(namespace.artifact(artifactSummary.getName(), artifactSummary.getVersion()));
}
assertIsClear(namespace);
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class OperationsDashboardHttpHandler method getScheduledDashboardRecords.
/**
* For a given time schedule, gets all the scheduled program run in the given time range
*
* @param schedule the schedule to get scheduled program run with
* @param startTimeSecs the start of the time range in seconds (inclusive, i.e. scheduled time larger or equal to the
* start will be returned)
* @param endTimeSecs the end of the time range in seconds (exclusive, i.e. scheduled time smaller than the end will
* be returned)
* @return a list of dashboard program run records with scheduled time as start time
* @throws Exception
*/
private List<DashboardProgramRunRecord> getScheduledDashboardRecords(ProgramSchedule schedule, long startTimeSecs, long endTimeSecs) throws Exception {
ProgramId programId = schedule.getProgramId();
// get all the scheduled run times within the given time range of the given program
List<ScheduledRuntime> scheduledRuntimes = timeSchedulerService.getAllScheduledRunTimes(programId, programId.getType().getSchedulableType(), startTimeSecs, endTimeSecs);
String userId = schedule.getProperties().get(ProgramOptionConstants.USER_ID);
String artifactId = schedule.getProperties().get(ProgramOptionConstants.ARTIFACT_ID);
ArtifactSummary artifactSummary = artifactId == null ? null : ArtifactSummary.from(GSON.fromJson(artifactId, ArtifactId.class));
// for each scheduled runtime, construct a dashboard record for it with the scheduled time as start time
return scheduledRuntimes.stream().map(scheduledRuntime -> new DashboardProgramRunRecord(programId.getNamespace(), artifactSummary, new DashboardProgramRunRecord.ApplicationNameVersion(programId.getApplication(), programId.getVersion()), programId.getType().name(), programId.getProgram(), null, userId, SCHEDULED, // convert the scheduled time from millis to seconds as start time
TimeUnit.MILLISECONDS.toSeconds(scheduledRuntime.getTime()), null, null, null, null, null)).collect(Collectors.toList());
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactPlugin.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/" + "versions/{artifact-version}/extensions/{plugin-type}/plugins/{plugin-name}")
public void getArtifactPlugin(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("plugin-type") String pluginType, @PathParam("plugin-name") String pluginName, @QueryParam("scope") @DefaultValue("user") final String scope, @QueryParam("artifactName") final String pluginArtifactName, @QueryParam("artifactVersion") String pluginVersion, @QueryParam("artifactScope") final String pluginScope, @QueryParam("limit") @DefaultValue("2147483647") String limit, @QueryParam("order") @DefaultValue("UNORDERED") String order) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException, InvalidArtifactRangeException {
NamespaceId namespace = Ids.namespace(namespaceId);
NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope);
final NamespaceId pluginArtifactNamespace = validateAndGetScopedNamespace(namespace, pluginScope);
ArtifactId parentArtifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
final ArtifactVersionRange pluginRange = pluginVersion == null ? null : ArtifactVersionRange.parse(pluginVersion);
int limitNumber = Integer.parseInt(limit);
limitNumber = limitNumber <= 0 ? Integer.MAX_VALUE : limitNumber;
ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order);
Predicate<ArtifactId> predicate = new Predicate<ArtifactId>() {
@Override
public boolean apply(ArtifactId input) {
// by default, the scoped namespace is for USER scope
return (((pluginScope == null && NamespaceId.SYSTEM.equals(input.getParent())) || pluginArtifactNamespace.equals(input.getParent())) && (pluginArtifactName == null || pluginArtifactName.equals(input.getArtifact())) && (pluginRange == null || pluginRange.versionIsInRange(new ArtifactVersion(input.getVersion()))));
}
};
try {
SortedMap<ArtifactDescriptor, PluginClass> plugins = artifactRepository.getPlugins(namespace, Id.Artifact.fromEntityId(parentArtifactId), pluginType, pluginName, predicate, limitNumber, sortOrder);
List<PluginInfo> pluginInfos = Lists.newArrayList();
// flatten the map
for (Map.Entry<ArtifactDescriptor, PluginClass> pluginsEntry : plugins.entrySet()) {
ArtifactDescriptor pluginArtifact = pluginsEntry.getKey();
ArtifactSummary pluginArtifactSummary = ArtifactSummary.from(pluginArtifact.getArtifactId());
PluginClass pluginClass = pluginsEntry.getValue();
try {
capabilityReader.checkAllEnabled(pluginClass.getRequirements().getCapabilities());
} catch (CapabilityNotAvailableException e) {
LOG.debug("Skipping plugin {} because of disabled capability", pluginClass, e);
continue;
}
pluginInfos.add(new PluginInfo(pluginClass, pluginArtifactSummary));
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(pluginInfos));
} catch (PluginNotExistsException e) {
responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage());
} catch (IOException e) {
LOG.error("Exception looking up plugins for artifact {}", parentArtifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store.");
}
}
use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactPlugins.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/extensions/{plugin-type}")
public void getArtifactPlugins(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("plugin-type") String pluginType, @QueryParam("scope") @DefaultValue("user") String scope) throws NamespaceNotFoundException, BadRequestException, ArtifactNotFoundException {
NamespaceId namespace = Ids.namespace(namespaceId);
NamespaceId artifactNamespace = validateAndGetScopedNamespace(namespace, scope);
ArtifactId artifactId = validateAndGetArtifactId(artifactNamespace, artifactName, artifactVersion);
try {
SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = artifactRepository.getPlugins(namespace, Id.Artifact.fromEntityId(artifactId), pluginType);
List<PluginSummary> pluginSummaries = Lists.newArrayList();
// flatten the map
for (Map.Entry<ArtifactDescriptor, Set<PluginClass>> pluginsEntry : plugins.entrySet()) {
ArtifactDescriptor pluginArtifact = pluginsEntry.getKey();
ArtifactSummary pluginArtifactSummary = ArtifactSummary.from(pluginArtifact.getArtifactId());
for (PluginClass pluginClass : pluginsEntry.getValue()) {
try {
capabilityReader.checkAllEnabled(pluginClass.getRequirements().getCapabilities());
} catch (CapabilityNotAvailableException e) {
LOG.debug("Skipping plugin {} because of disabled capability", pluginClass, e);
continue;
}
pluginSummaries.add(new PluginSummary(pluginClass.getName(), pluginClass.getType(), pluginClass.getCategory(), pluginClass.getClassName(), pluginArtifactSummary, pluginClass.getDescription()));
}
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(pluginSummaries));
} catch (IOException e) {
LOG.error("Exception looking up plugins for artifact {}", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading plugins for the artifact from the store.");
}
}
Aggregations