Search in sources :

Example 96 with ArtifactSummary

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();
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) HttpResponse(io.cdap.common.http.HttpResponse) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) URL(java.net.URL)

Example 97 with ArtifactSummary

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);
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ArtifactClient(io.cdap.cdap.client.ArtifactClient) DatasetSpecificationSummary(io.cdap.cdap.proto.DatasetSpecificationSummary) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord)

Example 98 with ArtifactSummary

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());
}
Also used : TriggerInfo(io.cdap.cdap.api.schedule.TriggerInfo) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) DashboardProgramRunRecord(io.cdap.cdap.proto.ops.DashboardProgramRunRecord) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) GET(javax.ws.rs.GET) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ProgramHeartbeatService(io.cdap.cdap.reporting.ProgramHeartbeatService) GsonBuilder(com.google.gson.GsonBuilder) ScheduledRuntime(io.cdap.cdap.proto.ScheduledRuntime) ArrayList(java.util.ArrayList) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Trigger(io.cdap.cdap.api.schedule.Trigger) QueryParam(javax.ws.rs.QueryParam) Gson(com.google.gson.Gson) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) TimeSchedulerService(io.cdap.cdap.internal.app.runtime.schedule.TimeSchedulerService) KerberosName(org.apache.hadoop.security.authentication.util.KerberosName) TriggeringScheduleInfoAdapter(io.cdap.cdap.internal.app.runtime.schedule.TriggeringScheduleInfoAdapter) TriggeringScheduleInfo(io.cdap.cdap.api.schedule.TriggeringScheduleInfo) AbstractAppFabricHttpHandler(io.cdap.cdap.gateway.handlers.util.AbstractAppFabricHttpHandler) Logger(org.slf4j.Logger) HttpResponder(io.cdap.http.HttpResponder) Scheduler(io.cdap.cdap.scheduler.Scheduler) Collection(java.util.Collection) ProgramId(io.cdap.cdap.proto.id.ProgramId) Set(java.util.Set) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) IOException(java.io.IOException) BadRequestException(io.cdap.cdap.common.BadRequestException) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) Collectors(java.util.stream.Collectors) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Constants(io.cdap.cdap.common.conf.Constants) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ProgramOptionConstants(io.cdap.cdap.internal.app.runtime.ProgramOptionConstants) Comparator(java.util.Comparator) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) Singleton(com.google.inject.Singleton) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) DashboardProgramRunRecord(io.cdap.cdap.proto.ops.DashboardProgramRunRecord) ProgramId(io.cdap.cdap.proto.id.ProgramId) ScheduledRuntime(io.cdap.cdap.proto.ScheduledRuntime)

Example 99 with ArtifactSummary

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.");
    }
}
Also used : CapabilityNotAvailableException(io.cdap.cdap.internal.capability.CapabilityNotAvailableException) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactVersionRange(io.cdap.cdap.api.artifact.ArtifactVersionRange) IOException(java.io.IOException) ArtifactSortOrder(io.cdap.cdap.proto.artifact.ArtifactSortOrder) Predicate(com.google.common.base.Predicate) PluginNotExistsException(io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) PluginInfo(io.cdap.cdap.proto.artifact.PluginInfo) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) PluginClass(io.cdap.cdap.api.plugin.PluginClass) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 100 with ArtifactSummary

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.");
    }
}
Also used : CapabilityNotAvailableException(io.cdap.cdap.internal.capability.CapabilityNotAvailableException) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) IOException(java.io.IOException) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) PluginSummary(io.cdap.cdap.proto.artifact.PluginSummary) PluginClass(io.cdap.cdap.api.plugin.PluginClass) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)152 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)86 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)80 Test (org.junit.Test)70 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)48 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)44 ProgramId (io.cdap.cdap.proto.id.ProgramId)44 Id (io.cdap.cdap.common.id.Id)36 ProfileId (io.cdap.cdap.proto.id.ProfileId)26 HttpResponse (io.cdap.common.http.HttpResponse)26 IOException (java.io.IOException)22 URL (java.net.URL)22 JsonObject (com.google.gson.JsonObject)18 NotFoundException (io.cdap.cdap.common.NotFoundException)18 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)16 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)16 File (java.io.File)16 Map (java.util.Map)16 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)14 KerberosPrincipalId (io.cdap.cdap.proto.id.KerberosPrincipalId)14