Search in sources :

Example 66 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId 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("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("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();
    // 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 || !"upgrade".equalsIgnoreCase(commandArgs[0])) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(UpgradeTool.class.getName() + " upgrade", "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.", options, "");
        System.exit(0);
    }
    ClientConfig clientConfig = getClientConfig(commandLine);
    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 ArtifactClient(clientConfig)));
        System.exit(0);
    }
    File errorDir = commandLine.hasOption("e") ? new File(commandLine.getOptionValue("e")) : null;
    if (errorDir != null) {
        if (!errorDir.exists()) {
            if (!errorDir.mkdirs()) {
                LOG.error("Unable to create error directory {}.", errorDir.getAbsolutePath());
                System.exit(1);
            }
        } else if (!errorDir.isDirectory()) {
            LOG.error("{} is not a directory.", errorDir.getAbsolutePath());
            System.exit(1);
        } else if (!errorDir.canWrite()) {
            LOG.error("Unable to write to error directory {}.", errorDir.getAbsolutePath());
            System.exit(1);
        }
    }
    UpgradeTool upgradeTool = new UpgradeTool(clientConfig, errorDir);
    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 upgraded {}.", appId);
        } else {
            LOG.info("{} did not need to be upgraded.", appId);
        }
        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) 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)

Example 67 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class SetProgramInstancesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    ApplicationId appId = cliConfig.getCurrentNamespace().app(programIdParts[0]);
    int numInstances = arguments.getInt(ArgumentName.NUM_INSTANCES.toString());
    switch(elementType) {
        case FLOWLET:
            if (programIdParts.length < 3) {
                throw new CommandInputError(this);
            }
            String flowId = programIdParts[1];
            String flowletName = programIdParts[2];
            FlowletId flowletId = appId.flow(flowId).flowlet(flowletName);
            programClient.setFlowletInstances(flowletId, numInstances);
            output.printf("Successfully set flowlet '%s' of flow '%s' of app '%s' to %d instances\n", flowId, flowletId, appId.getEntityName(), numInstances);
            break;
        case WORKER:
            if (programIdParts.length < 2) {
                throw new CommandInputError(this);
            }
            String workerName = programIdParts[1];
            ProgramId workerId = appId.worker(workerName);
            programClient.setWorkerInstances(workerId, numInstances);
            output.printf("Successfully set worker '%s' of app '%s' to %d instances\n", workerName, appId.getEntityName(), numInstances);
            break;
        case SERVICE:
            if (programIdParts.length < 2) {
                throw new CommandInputError(this);
            }
            String serviceName = programIdParts[1];
            ServiceId service = appId.service(serviceName);
            programClient.setServiceInstances(service, numInstances);
            output.printf("Successfully set service '%s' of app '%s' to %d instances\n", serviceName, appId.getEntityName(), numInstances);
            break;
        default:
            // TODO: remove this
            throw new IllegalArgumentException("Unrecognized program element type for scaling: " + elementType);
    }
}
Also used : CommandInputError(co.cask.cdap.cli.exception.CommandInputError) FlowletId(co.cask.cdap.proto.id.FlowletId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) ServiceId(co.cask.cdap.proto.id.ServiceId)

Example 68 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class ProgramClient method stopAll.

/**
   * Stops all currently running programs.
   */
public void stopAll(NamespaceId namespace) throws IOException, UnauthenticatedException, InterruptedException, TimeoutException, UnauthorizedException, ApplicationNotFoundException {
    List<ApplicationRecord> allApps = applicationClient.list(namespace);
    for (ApplicationRecord applicationRecord : allApps) {
        ApplicationId appId = new ApplicationId(namespace.getNamespace(), applicationRecord.getName(), applicationRecord.getAppVersion());
        List<ProgramRecord> programRecords = applicationClient.listPrograms(appId);
        for (ProgramRecord programRecord : programRecords) {
            try {
                ProgramId program = appId.program(programRecord.getType(), programRecord.getName());
                String status = this.getStatus(program);
                if (!status.equals("STOPPED")) {
                    try {
                        this.stop(program);
                    } catch (IOException ioe) {
                        // which can be due to the program already being stopped when calling stop on it.
                        if (!"STOPPED".equals(getStatus(program))) {
                            throw ioe;
                        }
                        // Most likely, there was a race condition that the program stopped between the time we checked its
                        // status and calling the stop method.
                        LOG.warn("Program {} is already stopped, proceeding even though the following exception is raised.", program, ioe);
                    }
                    this.waitForStatus(program, ProgramStatus.STOPPED, 60, TimeUnit.SECONDS);
                }
            } catch (ProgramNotFoundException e) {
            // IGNORE
            }
        }
    }
}
Also used : ProgramRecord(co.cask.cdap.proto.ProgramRecord) IOException(java.io.IOException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 69 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class LineageAdmin method getMetadataForRun.

/**
   * @return metadata associated with a run
   */
public Set<MetadataRecord> getMetadataForRun(ProgramRunId run) throws NotFoundException {
    entityExistenceVerifier.ensureExists(run);
    Set<NamespacedEntityId> runEntities = new HashSet<>(lineageStoreReader.getEntitiesForRun(run));
    // No entities associated with the run, but run exists.
    if (runEntities.isEmpty()) {
        return ImmutableSet.of();
    }
    RunId runId = RunIds.fromString(run.getRun());
    // The entities returned by lineageStore does not contain application
    ApplicationId application = run.getParent().getParent();
    runEntities.add(application);
    return metadataStore.getSnapshotBeforeTime(MetadataScope.USER, runEntities, RunIds.getTime(runId, TimeUnit.MILLISECONDS));
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) RunId(org.apache.twill.api.RunId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) HashSet(java.util.HashSet)

Example 70 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class MetadataHttpHandler method removeAppTags.

@DELETE
@Path("/namespaces/{namespace-id}/apps/{app-id}/metadata/tags")
public void removeAppTags(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId) throws NotFoundException {
    ApplicationId app = new ApplicationId(namespaceId, appId);
    metadataAdmin.removeTags(app);
    responder.sendString(HttpResponseStatus.OK, String.format("Tags for app %s deleted successfully.", app));
}
Also used : ApplicationId(co.cask.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

ApplicationId (co.cask.cdap.proto.id.ApplicationId)234 Test (org.junit.Test)123 ProgramId (co.cask.cdap.proto.id.ProgramId)73 AppRequest (co.cask.cdap.proto.artifact.AppRequest)64 ApplicationManager (co.cask.cdap.test.ApplicationManager)49 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)45 ETLStage (co.cask.cdap.etl.proto.v2.ETLStage)44 NamespaceId (co.cask.cdap.proto.id.NamespaceId)43 Table (co.cask.cdap.api.dataset.table.Table)37 StructuredRecord (co.cask.cdap.api.data.format.StructuredRecord)36 Schema (co.cask.cdap.api.data.schema.Schema)34 ETLBatchConfig (co.cask.cdap.etl.proto.v2.ETLBatchConfig)32 WorkflowManager (co.cask.cdap.test.WorkflowManager)31 Path (javax.ws.rs.Path)31 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)29 StreamId (co.cask.cdap.proto.id.StreamId)28 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)26 ArrayList (java.util.ArrayList)25 HashSet (java.util.HashSet)24 NotFoundException (co.cask.cdap.common.NotFoundException)23