use of com.netflix.spinnaker.halyard.config.model.v1.node.Subscription in project halyard by spinnaker.
the class SubscriptionController method addSubscription.
@RequestMapping(value = "/", method = RequestMethod.POST)
DaemonTask<Halconfig, Void> addSubscription(@PathVariable String deploymentName, @PathVariable String pubsubName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawSubscription) {
Subscription subscription = objectMapper.convertValue(rawSubscription, Pubsubs.translateSubscriptionType(pubsubName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
builder.setSeverity(severity);
builder.setUpdate(() -> subscriptionService.addSubscription(deploymentName, pubsubName, subscription));
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> subscriptionService.validateSubscription(deploymentName, pubsubName, subscription.getName());
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
return DaemonTaskHandler.submitTask(builder::build, "Add the " + subscription.getName() + " subscription");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Subscription in project halyard by spinnaker.
the class SubscriptionService method getAllSubscriptions.
public List<Subscription> getAllSubscriptions(String deploymentName, String pubsubName) {
NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setPubsub(pubsubName).withAnySubscription();
List<Subscription> matchingSubscriptions = lookupService.getMatchingNodesOfType(filter, Subscription.class);
if (matchingSubscriptions.size() == 0) {
throw new ConfigNotFoundException(new ConfigProblemBuilder(Severity.FATAL, "No subscriptions could be found").build());
} else {
return matchingSubscriptions;
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Subscription in project halyard by spinnaker.
the class AbstractAddSubscriptionCommand method executeThis.
@Override
protected void executeThis() {
String subscriptionName = getSubscriptionName();
Subscription subscription = buildSubscription(subscriptionName);
String pubsubName = getPubsubName();
String currentDeployment = getCurrentDeployment();
new OperationHandler<Void>().setFailureMesssage("Failed to add subscription " + subscriptionName + " for pubsub " + pubsubName + ".").setSuccessMessage("Successfully added subscription " + subscriptionName + " for pubsub " + pubsubName + ".").setOperation(Daemon.addSubscription(currentDeployment, pubsubName, !noValidate, subscription)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Subscription in project halyard by spinnaker.
the class SubscriptionController method setSubscription.
@RequestMapping(value = "/subscription/{subscriptionName:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setSubscription(@PathVariable String deploymentName, @PathVariable String pubsubName, @PathVariable String subscriptionName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawSubscription) {
Subscription subscription = objectMapper.convertValue(rawSubscription, Pubsubs.translateSubscriptionType(pubsubName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
builder.setUpdate(() -> subscriptionService.setSubscription(deploymentName, pubsubName, subscriptionName, subscription));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> subscriptionService.validateSubscription(deploymentName, pubsubName, subscription.getName());
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
return DaemonTaskHandler.submitTask(builder::build, "Edit the " + subscriptionName + " subscription");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Subscription in project halyard by spinnaker.
the class AbstractEditSubscriptionCommand method executeThis.
@Override
protected void executeThis() {
String subscriptionName = getSubscriptionName();
String pubsubName = getPubsubName();
String currentDeployment = getCurrentDeployment();
// Disable validation here, since we don't want an illegal config to prevent us from fixing it.
Subscription subscription = new OperationHandler<Subscription>().setFailureMesssage("Failed to get subscription " + subscriptionName + " for pubsub " + pubsubName + ".").setOperation(Daemon.getSubscription(currentDeployment, pubsubName, subscriptionName, false)).get();
int originaHash = subscription.hashCode();
subscription = editSubscription((T) subscription);
if (originaHash == subscription.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>().setFailureMesssage("Failed to edit subscription " + subscriptionName + " for pubsub " + pubsubName + ".").setSuccessMessage("Successfully edited subscription " + subscriptionName + " for pubsub " + pubsubName + ".").setOperation(Daemon.setSubscription(currentDeployment, pubsubName, subscriptionName, !noValidate, subscription)).get();
}
Aggregations