}
List<String> cmdline = opts._();
String name = cmdline.remove(0);
Service s = jpm.getService(name);
if (opts.remove()) {
if (!jpm.hasAccess()) {
error("No write access to remove service %s", name);
return;
}
if (s == null) {
error("No such service %s to remove", name);
return;
}
s.stop();
s.remove();
return;
}
if (opts.create() != null) {
if (s != null) {
error("Service already exists, cannot be created: %s. Update or remove it first", name);
return;
}
ArtifactData target = jpm.getCandidate(opts.create());
if (target == null)
return;
ServiceData data = null; // TODO target.service;
updateServiceData(data, opts);
String result = jpm.createService(data);
if (result != null)
error("Create service failed: %s", result);
return;
}
if (s == null) {
error("No such service: %s", name);
return;
}
ServiceData data = s.getServiceData();
if (updateServiceData(data, opts) || opts.coordinates() != null || opts.update()) {
if (!jpm.hasAccess()) {
error("No write access to update service %s", name);
return;
}
//
// Check if we have to update the underlying artifact
// This is triggered by --coordinate, which provides
// the new coordinate or just --update which reuses the
// old coordinate without version
//
if (opts.coordinates() != null || opts.update()) {
String coordinates = opts.coordinates();
if (coordinates == null) {
error("No coordinate found in old service record");
return;
}
int n = coordinates.indexOf('@');
if (n > 0)
coordinates = coordinates.substring(0, n);
trace("Updating from coordinate: %s", coordinates);
ArtifactData target = jpm.getCandidate(coordinates);
if (target == null) {
error("No candidates found for %s (%s)", coordinates, opts.staged() ? "staged" : "only masters");
return;
}
// data.dependencies.clear();
// data.dependencies.add(target.file);
// data.dependencies.addAll(target.dependencies);
// data.coordinates = coordinates;
}
String result = jpm.createService(data);
if (result != null)
error("Update service failed: %s", result);
else if (s.isRunning())
warning("Changes will not affect the currently running process");
}
Data.details(data, out);
}