Search in sources :

Example 1 with ArtifactScope

use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.

the class Artifacts method toArtifactId.

/**
 * Converts a {@link ArtifactId} to {@link co.cask.cdap.proto.id.ArtifactId}.
 *
 * @param namespaceId the user namespace to use
 * @param artifactId the artifact id to convert
 */
public static co.cask.cdap.proto.id.ArtifactId toArtifactId(NamespaceId namespaceId, ArtifactId artifactId) {
    ArtifactScope scope = artifactId.getScope();
    NamespaceId artifactNamespace = scope == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : namespaceId;
    return artifactNamespace.artifact(artifactId.getName(), artifactId.getVersion().getVersion());
}
Also used : ArtifactScope(co.cask.cdap.api.artifact.ArtifactScope) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 2 with ArtifactScope

use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.

the class ListArtifactVersionsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
    List<ArtifactSummary> artifactSummaries;
    if (scopeStr == null) {
        artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName);
    } else {
        ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
        artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName, scope);
    }
    Table table = Table.builder().setHeader("name", "version", "scope").setRows(artifactSummaries, new RowMaker<ArtifactSummary>() {

        @Override
        public List<?> makeRow(ArtifactSummary object) {
            return Lists.newArrayList(object.getName(), object.getVersion(), object.getScope().name());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : ArtifactScope(co.cask.cdap.api.artifact.ArtifactScope) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker)

Example 3 with ArtifactScope

use of co.cask.cdap.api.artifact.ArtifactScope 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(co.cask.cdap.api.artifact.ArtifactScope) Table(co.cask.cdap.cli.util.table.Table) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo) RowMaker(co.cask.cdap.cli.util.RowMaker) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 4 with ArtifactScope

use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.

the class PluginSpec method readExternal.

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    type = in.readUTF();
    name = in.readUTF();
    properties = (Map<String, String>) in.readObject();
    boolean artifactExists = in.readBoolean();
    if (artifactExists) {
        String artifactName = in.readUTF();
        ArtifactVersion artifactVersion = new ArtifactVersion(in.readUTF());
        ArtifactScope artifactScope = ArtifactScope.valueOf(in.readUTF());
        artifact = new ArtifactId(artifactName, artifactVersion, artifactScope);
    }
}
Also used : ArtifactScope(co.cask.cdap.api.artifact.ArtifactScope) ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactId(co.cask.cdap.api.artifact.ArtifactId)

Example 5 with ArtifactScope

use of co.cask.cdap.api.artifact.ArtifactScope in project cdap by caskdata.

the class CreateAppCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    ApplicationId appId = parseApplicationId(arguments);
    String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
    String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
    ArtifactScope artifactScope = ArtifactScope.valueOf(arguments.get(ArgumentName.SCOPE.toString()).toUpperCase());
    ArtifactSummary artifact = new ArtifactSummary(artifactName, artifactVersion, artifactScope);
    JsonObject config = new JsonObject();
    String ownerPrincipal = null;
    Boolean updateSchedules = null;
    PreviewConfig previewConfig = null;
    String configPath = arguments.getOptional(ArgumentName.APP_CONFIG_FILE.toString());
    if (configPath != null) {
        File configFile = resolver.resolvePathToFile(configPath);
        try (FileReader reader = new FileReader(configFile)) {
            AppRequest<JsonObject> appRequest = GSON.fromJson(reader, configType);
            config = appRequest.getConfig();
            ownerPrincipal = appRequest.getOwnerPrincipal();
            previewConfig = appRequest.getPreview();
            updateSchedules = appRequest.canUpdateSchedules();
        }
    }
    AppRequest<JsonObject> appRequest = new AppRequest<>(artifact, config, previewConfig, ownerPrincipal, updateSchedules);
    applicationClient.deploy(appId, appRequest);
    output.println("Successfully created application");
}
Also used : ArtifactScope(co.cask.cdap.api.artifact.ArtifactScope) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) JsonObject(com.google.gson.JsonObject) FileReader(java.io.FileReader) ApplicationId(co.cask.cdap.proto.id.ApplicationId) File(java.io.File) PreviewConfig(co.cask.cdap.proto.artifact.preview.PreviewConfig) AppRequest(co.cask.cdap.proto.artifact.AppRequest)

Aggregations

ArtifactScope (co.cask.cdap.api.artifact.ArtifactScope)10 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)3 Table (co.cask.cdap.cli.util.table.Table)3 ArtifactId (co.cask.cdap.proto.id.ArtifactId)3 File (java.io.File)3 FileReader (java.io.FileReader)3 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)2 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)2 RowMaker (co.cask.cdap.cli.util.RowMaker)2 AppRequest (co.cask.cdap.proto.artifact.AppRequest)2 ApplicationId (co.cask.cdap.proto.id.ApplicationId)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 JsonObject (com.google.gson.JsonObject)2 Map (java.util.Map)2 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)1 ArtifactVersionRange (co.cask.cdap.api.artifact.ArtifactVersionRange)1 InvalidArtifactRangeException (co.cask.cdap.api.artifact.InvalidArtifactRangeException)1 DefaultApplicationSpecification (co.cask.cdap.internal.app.DefaultApplicationSpecification)1 DefaultScheduleBuilder (co.cask.cdap.internal.app.runtime.schedule.DefaultScheduleBuilder)1 ScheduleCreationSpec (co.cask.cdap.internal.schedule.ScheduleCreationSpec)1