use of com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub in project halyard by spinnaker.
the class PubsubService method setEnabled.
public void setEnabled(String deploymentName, String pubsubName, boolean enabled) {
Pubsub pubsub = getPubsub(deploymentName, pubsubName);
pubsub.setEnabled(enabled);
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub in project halyard by spinnaker.
the class PubsubService method getPubsub.
public Pubsub getPubsub(String deploymentName, String pubsubName) {
NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setPubsub(pubsubName);
List<Pubsub> matching = lookupService.getMatchingNodesOfType(filter, Pubsub.class);
switch(matching.size()) {
case 0:
throw new ConfigNotFoundException(new ConfigProblemBuilder(Severity.FATAL, "No pubsub with name \"" + pubsubName + "\" could be found").setRemediation("Create a new pubsub with name \"" + pubsubName + "\"").build());
case 1:
return matching.get(0);
default:
throw new IllegalConfigException(new ConfigProblemBuilder(Severity.FATAL, "More than one pubsub with name \"" + pubsubName + "\" found").setRemediation("Manually delete or rename duplicate pubsubs with name \"" + pubsubName + "\" in your halconfig file").build());
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub 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.Pubsub in project halyard by spinnaker.
the class PubsubController method setPubsub.
@RequestMapping(value = "/{pubsubName:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setPubsub(@PathVariable String deploymentName, @PathVariable String pubsubName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawPubsub) {
Pubsub pubsub = objectMapper.convertValue(rawPubsub, Pubsubs.translatePubsubType(pubsubName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> pubsub.stageLocalFiles(configPath));
builder.setUpdate(() -> pubsubService.setPubsub(deploymentName, pubsub));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> pubsubService.validatePubsub(deploymentName, pubsubName);
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit the " + pubsubName + " pubsub");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub 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