Search in sources :

Example 1 with Subscription

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");
}
Also used : UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) Subscription(com.netflix.spinnaker.halyard.config.model.v1.node.Subscription) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with 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;
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) Subscription(com.netflix.spinnaker.halyard.config.model.v1.node.Subscription) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Example 3 with Subscription

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();
}
Also used : Subscription(com.netflix.spinnaker.halyard.config.model.v1.node.Subscription) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 4 with Subscription

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");
}
Also used : UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) Subscription(com.netflix.spinnaker.halyard.config.model.v1.node.Subscription) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with 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();
}
Also used : Subscription(com.netflix.spinnaker.halyard.config.model.v1.node.Subscription) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Aggregations

Subscription (com.netflix.spinnaker.halyard.config.model.v1.node.Subscription)7 Pubsub (com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub)3 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)2 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)2 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)2 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)1 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1