Search in sources :

Example 1 with ArtifactClient

use of co.cask.cdap.client.ArtifactClient 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 streams
    for (StreamDetail streamDetail : getStreamClient().list(namespace)) {
        getStreamClient().delete(namespace.stream(streamDetail.getName()));
    }
    // 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(co.cask.cdap.api.artifact.ArtifactSummary) StreamDetail(co.cask.cdap.proto.StreamDetail) ArtifactClient(co.cask.cdap.client.ArtifactClient) DatasetSpecificationSummary(co.cask.cdap.proto.DatasetSpecificationSummary) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 2 with ArtifactClient

use of co.cask.cdap.client.ArtifactClient in project cdap by caskdata.

the class UpgradeTool method main.

public static void main(String[] args) throws Exception {
    Options options = new Options().addOption(new Option("h", "help", false, "Print this usage message.")).addOption(new Option("u", "uri", true, "CDAP instance URI to interact with in the format " + "[http[s]://]<hostname>:<port>. Defaults to localhost:11015.")).addOption(new Option("a", "accesstoken", true, "File containing the access token to use when interacting " + "with a secure CDAP instance.")).addOption(new Option("t", "timeout", true, "Timeout in milliseconds to use when interacting with the " + "CDAP RESTful APIs. Defaults to " + DEFAULT_READ_TIMEOUT_MILLIS + ".")).addOption(new Option("n", "namespace", true, "Namespace to perform the upgrade in. If none is given, " + "pipelines in all namespaces will be upgraded.")).addOption(new Option("p", "pipeline", true, "Name of the pipeline to upgrade. If specified, a namespace " + "must also be given.")).addOption(new Option("v", "version", true, "Pipeline version to upgrade to. This should only be specified if " + "you want to upgrade to a version that is not the same as the version of this tool.")).addOption(new Option("r", "rerun", false, "Whether to re-run upgrade of pipelines. " + "This will re-run the upgrade for any pipelines that are using the current pipeline version in addition " + "to running upgrade for any old pipelines.")).addOption(new Option("f", "configfile", true, "File containing old application details to update. " + "The file contents are expected to be in the same format as the request body for creating an " + "ETL application from one of the etl artifacts. " + "It is expected to be a JSON Object containing 'artifact' and 'config' fields." + "The value for 'artifact' must be a JSON Object that specifies the artifact scope, name, and version. " + "The value for 'config' must be a JSON Object specifies the source, transforms, and sinks of the pipeline, " + "as expected by older versions of the etl artifacts.")).addOption(new Option("o", "outputfile", true, "File to write the converted application details provided in " + "the configfile option. If none is given, results will be written to the input file + '.converted'. " + "The contents of this file can be sent directly to CDAP to update or create an application.")).addOption(new Option("od", "outputdir", true, "Directory to write the application request that would be used " + "to upgrade the pipeline(s). This should only be used with the 'dryrun' command, not the 'upgrade' command. " + "The contents of the app request files can be sent directly to CDAP to update or create an application.")).addOption(new Option("e", "errorDir", true, "Optional directory to write any upgraded pipeline configs that " + "failed to upgrade. The problematic configs can then be manually edited and upgraded separately. " + "Upgrade errors may happen for pipelines that use plugins that are not backwards compatible. " + "This directory must be writable by the user that is running this tool."));
    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);
    String[] commandArgs = commandLine.getArgs();
    String command = commandArgs.length > 0 ? commandArgs[0] : null;
    // if help is an option, or if there isn't a single 'upgrade' command, print usage and exit.
    if (commandLine.hasOption("h") || commandArgs.length != 1 || (!"downgrade".equalsIgnoreCase(command) && !"upgrade".equalsIgnoreCase(command) && !"dryrun".equalsIgnoreCase(command))) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(UpgradeTool.class.getName() + " upgrade|downgrade|dryrun", "Upgrades old pipelines to the current version. If the plugins used are not backward-compatible, " + "the attempted upgrade config will be written to the error directory for a manual upgrade. " + "If 'dryrun' is used as the command instead of 'upgrade', pipelines will not be upgraded, but the " + "application update requests will instead be written as files to the specified outputdir.", options, "");
        System.exit(0);
    }
    ClientConfig clientConfig = getClientConfig(commandLine);
    boolean downgrade = "downgrade".equalsIgnoreCase(command);
    String newVersion = commandLine.hasOption("v") ? commandLine.getOptionValue("v") : ETLVersion.getVersion();
    boolean includeCurrentVersion = commandLine.hasOption("r");
    if (commandLine.hasOption("f")) {
        String inputFilePath = commandLine.getOptionValue("f");
        String outputFilePath = commandLine.hasOption("o") ? commandLine.getOptionValue("o") : inputFilePath + ".new";
        convertFile(inputFilePath, outputFilePath, new Upgrader(new NamespaceClient(clientConfig), new ArtifactClient(clientConfig), newVersion, includeCurrentVersion, downgrade));
        System.exit(0);
    }
    File errorDir = commandLine.hasOption("e") ? new File(commandLine.getOptionValue("e")) : null;
    if (errorDir != null) {
        ensureDirExists(errorDir);
    }
    boolean dryrun = "dryrun".equalsIgnoreCase(command);
    File outputDir = null;
    if (dryrun) {
        if (!commandLine.hasOption("od")) {
            LOG.error("When performing a dryrun, an outputdir must be specified using the -od option.");
            System.exit(1);
        }
        outputDir = new File(commandLine.getOptionValue("od"));
        ensureDirExists(outputDir);
    }
    UpgradeTool upgradeTool = new UpgradeTool(clientConfig, errorDir, outputDir, newVersion, includeCurrentVersion, downgrade, dryrun);
    String namespace = commandLine.getOptionValue("n");
    String pipelineName = commandLine.getOptionValue("p");
    if (pipelineName != null) {
        if (namespace == null) {
            throw new IllegalArgumentException("Must specify a namespace when specifying a pipeline.");
        }
        ApplicationId appId = new ApplicationId(namespace, pipelineName);
        if (upgradeTool.upgrade(appId)) {
            LOG.info("Successfully {}d {}.", command, appId);
        } else {
            LOG.info("{} did not need to be {}d.", appId, command);
        }
        System.exit(0);
    }
    if (namespace != null) {
        printUpgraded(upgradeTool.upgrade(new NamespaceId(namespace)));
        System.exit(0);
    }
    printUpgraded(upgradeTool.upgrade());
}
Also used : Options(org.apache.commons.cli.Options) Upgrader(co.cask.cdap.etl.tool.config.Upgrader) HelpFormatter(org.apache.commons.cli.HelpFormatter) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) NamespaceClient(co.cask.cdap.client.NamespaceClient) ArtifactClient(co.cask.cdap.client.ArtifactClient) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ClientConfig(co.cask.cdap.client.config.ClientConfig) ApplicationId(co.cask.cdap.proto.id.ApplicationId) File(java.io.File)

Aggregations

ArtifactClient (co.cask.cdap.client.ArtifactClient)2 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 NamespaceClient (co.cask.cdap.client.NamespaceClient)1 ClientConfig (co.cask.cdap.client.config.ClientConfig)1 Upgrader (co.cask.cdap.etl.tool.config.Upgrader)1 ApplicationRecord (co.cask.cdap.proto.ApplicationRecord)1 DatasetSpecificationSummary (co.cask.cdap.proto.DatasetSpecificationSummary)1 StreamDetail (co.cask.cdap.proto.StreamDetail)1 ApplicationId (co.cask.cdap.proto.id.ApplicationId)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 File (java.io.File)1 BasicParser (org.apache.commons.cli.BasicParser)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1