Search in sources :

Example 1 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class DescribeArtifactPluginCommand 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 pluginType = arguments.get(ArgumentName.PLUGIN_TYPE.toString());
    String pluginName = arguments.get(ArgumentName.PLUGIN_NAME.toString());
    List<PluginInfo> pluginInfos;
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    if (scopeStr == null) {
        pluginInfos = artifactClient.getPluginInfo(artifactId, pluginType, pluginName);
    } else {
        pluginInfos = artifactClient.getPluginInfo(artifactId, pluginType, pluginName, ArtifactScope.valueOf(scopeStr.toUpperCase()));
    }
    Table table = Table.builder().setHeader("type", "name", "classname", "description", "properties", "artifact").setRows(pluginInfos, new RowMaker<PluginInfo>() {

        @Override
        public List<?> makeRow(PluginInfo object) {
            return Lists.newArrayList(object.getType(), object.getName(), object.getClassName(), object.getDescription(), GSON.toJson(object.getProperties()), object.getArtifact().toString());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) RowMaker(io.cdap.cdap.cli.util.RowMaker) PluginInfo(io.cdap.cdap.proto.artifact.PluginInfo)

Example 2 with ArtifactId

use of io.cdap.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);
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) Table(io.cdap.cdap.cli.util.table.Table) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) RowMaker(io.cdap.cdap.cli.util.RowMaker) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 3 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class ArtifactCacheHttpHandlerInternal method fetchArtifact.

@GET
@Path("peers/{peer}/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}")
public void fetchArtifact(HttpRequest request, HttpResponder responder, @PathParam("peer") String peer, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion) throws Exception {
    ArtifactId artifactId = new ArtifactId(namespaceId, artifactName, artifactVersion);
    try {
        String endpoint = tetheringStore.getPeer(peer).getEndpoint();
        RemoteClientFactory factory = new RemoteClientFactory(new NoOpDiscoveryServiceClient(endpoint), new NoOpInternalAuthenticator(), remoteAuthenticator);
        HttpRequestConfig config = new DefaultHttpRequestConfig(true);
        RemoteClient remoteClient = factory.createRemoteClient("", config, Constants.Gateway.INTERNAL_API_VERSION_3);
        File artifactPath = cache.getArtifact(artifactId, peer, remoteClient);
        Location artifactLocation = Locations.toLocation(artifactPath);
        responder.sendContent(HttpResponseStatus.OK, new LocationBodyProducer(artifactLocation), new DefaultHttpHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM));
    } catch (Exception ex) {
        if (ex instanceof HttpErrorStatusProvider) {
            HttpResponseStatus status = HttpResponseStatus.valueOf(((HttpErrorStatusProvider) ex).getStatusCode());
            responder.sendString(status, exceptionToJson(ex));
        } else {
            responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, exceptionToJson(ex));
        }
    }
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) NoOpInternalAuthenticator(io.cdap.cdap.common.internal.remote.NoOpInternalAuthenticator) HttpErrorStatusProvider(io.cdap.cdap.api.common.HttpErrorStatusProvider) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpRequestConfig(io.cdap.common.http.HttpRequestConfig) LocationBodyProducer(io.cdap.cdap.common.http.LocationBodyProducer) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) RemoteClient(io.cdap.cdap.common.internal.remote.RemoteClient) File(java.io.File) Location(org.apache.twill.filesystem.Location) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class ArtifactLocalizer method preloadArtifacts.

public void preloadArtifacts(Set<String> artifactNames) throws IOException, ArtifactNotFoundException {
    ArtifactManager artifactManager = artifactManagerFactory.create(NamespaceId.SYSTEM, RetryStrategies.fromConfiguration(cConf, Constants.Service.TASK_WORKER + "."));
    for (ArtifactInfo info : artifactManager.listArtifacts()) {
        if (artifactNames.contains(info.getName()) && info.getParents().isEmpty()) {
            String className = info.getClasses().getApps().stream().findFirst().map(ApplicationClass::getClassName).orElse(null);
            LOG.info("Preloading artifact {}:{}-{}", info.getScope(), info.getName(), info.getVersion());
            ArtifactId artifactId = NamespaceId.SYSTEM.artifact(info.getName(), info.getVersion());
            try {
                fetchArtifact(artifactId);
            } catch (Exception e) {
                LOG.debug("Failed to preload artifact {}", artifactId);
            }
        }
    }
}
Also used : ArtifactManager(io.cdap.cdap.api.artifact.ArtifactManager) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) IOException(java.io.IOException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException)

Example 5 with ArtifactId

use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class DataPipelineServiceTest method setupTest.

@BeforeClass
public static void setupTest() throws Exception {
    ArtifactId appArtifactId = NamespaceId.SYSTEM.artifact("cdap-data-pipeline", "6.0.0");
    setupBatchArtifacts(appArtifactId, DataPipelineApp.class);
    enableCapability("pipeline");
    ApplicationId pipeline = NamespaceId.SYSTEM.app("pipeline");
    appManager = getApplicationManager(pipeline);
    waitForAppToDeploy(appManager, pipeline);
    serviceManager = appManager.getServiceManager(io.cdap.cdap.etl.common.Constants.STUDIO_SERVICE_NAME);
    serviceManager.startAndWaitForGoodRun(ProgramRunStatus.RUNNING, 2, TimeUnit.MINUTES);
    serviceURI = serviceManager.getServiceURL(1, TimeUnit.MINUTES).toURI();
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) BeforeClass(org.junit.BeforeClass)

Aggregations

ArtifactId (io.cdap.cdap.proto.id.ArtifactId)107 Test (org.junit.Test)59 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)47 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)34 IOException (java.io.IOException)25 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)21 ProgramId (io.cdap.cdap.proto.id.ProgramId)21 Id (io.cdap.cdap.common.id.Id)20 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)20 File (java.io.File)17 PluginClass (io.cdap.cdap.api.plugin.PluginClass)16 Path (javax.ws.rs.Path)16 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)15 Set (java.util.Set)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 Location (org.apache.twill.filesystem.Location)14 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)13 ArtifactDetail (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)13 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)11 Map (java.util.Map)10