use of com.netflix.spinnaker.halyard.config.model.v1.node.MetricStore in project halyard by spinnaker.
the class AbstractEditMetricStoreCommand method executeThis.
@Override
protected void executeThis() {
String currentDeployment = getCurrentDeployment();
String metricStoreType = getMetricStoreType().getId();
// Disable validation here, since we don't want an illegal config to prevent us from fixing it.
MetricStore metricStore = new OperationHandler<MetricStore>().setOperation(Daemon.getMetricStore(currentDeployment, metricStoreType, false)).setFailureMesssage("Failed to get " + metricStoreType + " method.").get();
int originalHash = metricStore.hashCode();
metricStore = editMetricStore((T) metricStore);
if (originalHash == metricStore.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>().setOperation(Daemon.setMetricStore(currentDeployment, metricStoreType, !noValidate, metricStore)).setFailureMesssage("Failed to edit " + metricStoreType + " method.").setSuccessMessage("Successfully edited " + metricStoreType + " method.").get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.MetricStore in project halyard by spinnaker.
the class MetricStoresController method setMetricStore.
@RequestMapping(value = "/{metricStoreType:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setMetricStore(@PathVariable String deploymentName, @PathVariable String metricStoreType, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawMetricStore) {
MetricStore metricStore = objectMapper.convertValue(rawMetricStore, MetricStores.translateMetricStoreType(metricStoreType));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path stagingPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> metricStore.stageLocalFiles(stagingPath));
builder.setSeverity(severity);
builder.setUpdate(() -> metricStoresService.setMetricStore(deploymentName, metricStore));
builder.setValidate(ProblemSet::new);
if (validate) {
builder.setValidate(() -> metricStoresService.validateMetricStore(deploymentName, metricStoreType));
}
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(stagingPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit " + metricStoreType + " metric store");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.MetricStore in project halyard by spinnaker.
the class MetricStoresService method setMetricStoreEnabled.
public void setMetricStoreEnabled(String deploymentName, String metricStoreType, boolean enabled) {
MetricStore metricStore = getMetricStore(deploymentName, metricStoreType);
metricStore.setEnabled(enabled);
setMetricStore(deploymentName, metricStore);
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.MetricStore in project halyard by spinnaker.
the class MetricStoresService method getMetricStore.
public MetricStore getMetricStore(String deploymentName, String metricStoreType) {
NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setMetricStores().setMetricStore(metricStoreType);
List<MetricStore> matching = lookupService.getMatchingNodesOfType(filter, MetricStore.class);
try {
switch(matching.size()) {
case 0:
MetricStore metricStores = MetricStores.translateMetricStoreType(metricStoreType).newInstance();
setMetricStore(deploymentName, metricStores);
return metricStores;
case 1:
return matching.get(0);
default:
throw new RuntimeException("It shouldn't be possible to have multiple metricStore nodes of the same type. This is a bug.");
}
} catch (InstantiationException | IllegalAccessException e) {
throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Can't create an empty metric store node " + "for metricStore type \"" + metricStoreType + "\"").build());
}
}
Aggregations