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());
}
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);
}
}
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
}
}
}
}
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));
}
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));
}
Aggregations