Search in sources :

Example 1 with MetricStore

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

Example 2 with MetricStore

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

Example 3 with MetricStore

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

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

Aggregations

MetricStore (com.netflix.spinnaker.halyard.config.model.v1.node.MetricStore)4 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)1 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)1 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)1 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)1 Path (java.nio.file.Path)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1