Search in sources :

Example 6 with ArtifactScope

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

the class SetArtifactPropertiesCommand 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());
    String scopeStr = arguments.get(ArgumentName.SCOPE.toString());
    ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
    NamespaceId namespace = scope == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : cliConfig.getCurrentNamespace();
    ArtifactId artifactId = namespace.artifact(artifactName, artifactVersion);
    String propertiesFilePath = arguments.get(ArgumentName.LOCAL_FILE_PATH.toString());
    File propertiesFile = resolver.resolvePathToFile(propertiesFilePath);
    try (Reader reader = new FileReader(propertiesFile)) {
        ArtifactProperties properties;
        try {
            properties = GSON.fromJson(reader, ArtifactProperties.class);
        } catch (Exception e) {
            throw new RuntimeException("Error parsing file contents. Please check that it is a valid JSON object, " + "and that it contains a 'properties' key whose value is a JSON object of the " + "artifact properties.", e);
        }
        artifactClient.writeProperties(artifactId, properties.properties);
    }
}
Also used : ArtifactScope(co.cask.cdap.api.artifact.ArtifactScope) ArtifactId(co.cask.cdap.proto.id.ArtifactId) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) NamespaceId(co.cask.cdap.proto.id.NamespaceId) File(java.io.File)

Example 7 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)

Example 8 with ArtifactScope

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

the class DescribeArtifactCommand 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);
    }
    Table table = Table.builder().setHeader("name", "version", "scope", "app classes", "plugin classes", "properties", "parents").setRows(ImmutableList.of((List<String>) ImmutableList.of(info.getName(), info.getVersion(), info.getScope().name(), GSON.toJson(info.getClasses().getApps()), GSON.toJson(info.getClasses().getPlugins()), GSON.toJson(info.getProperties()), Joiner.on('/').join(info.getParents())))).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)

Example 9 with ArtifactScope

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

the class UpdateAppCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String appName = arguments.get(ArgumentName.APP.toString());
    ApplicationId appId = cliConfig.getCurrentNamespace().app(appName);
    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 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, CONFIG_TYPE);
            config = appRequest.getConfig();
        }
    }
    AppRequest<JsonObject> appRequest = new AppRequest<>(artifact, config);
    applicationClient.update(appId, appRequest);
    output.println("Successfully updated 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) AppRequest(co.cask.cdap.proto.artifact.AppRequest)

Aggregations

ArtifactScope (co.cask.cdap.api.artifact.ArtifactScope)9 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 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 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)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 PreviewConfig (co.cask.cdap.proto.artifact.preview.PreviewConfig)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1