use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class DistributedDeployer method flushInfrastructureCaches.
@Override
public void flushInfrastructureCaches(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, SpinnakerRuntimeSettings runtimeSettings) {
try {
Jedis jedis = (Jedis) serviceProvider.getDeployableService(SpinnakerService.Type.REDIS).connectToPrimaryService(deploymentDetails, runtimeSettings);
RedisService.flushKeySpace(jedis, "com.netflix.spinnaker.clouddriver*");
} catch (Exception e) {
throw new HalException(Problem.Severity.FATAL, "Failed to flush redis cache: " + e.getMessage());
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class LocalDeployer method flushInfrastructureCaches.
@Override
public void flushInfrastructureCaches(LocalServiceProvider serviceProvider, DeploymentDetails deploymentDetails, SpinnakerRuntimeSettings runtimeSettings) {
try {
Jedis jedis = new Jedis(runtimeSettings.getServiceSettings((SpinnakerService) serviceProvider.getLocalService(SpinnakerService.Type.REDIS)).getBaseUrl());
RedisService.flushKeySpace(jedis, ClouddriverService.REDIS_KEY_SPACE);
} catch (Exception e) {
throw new HalException(Problem.Severity.FATAL, "Unable to flush key space: " + e.getMessage(), e);
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class DaemonTaskHandler method reduceChildren.
public static <U, T> DaemonResponse<U> reduceChildren(U base, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner) {
DaemonTask task = getTask();
if (task != null) {
U responseBody = base;
ProblemSet problemSet = new ProblemSet();
DaemonResponse<U> response = new DaemonResponse<>(responseBody, problemSet);
return (DaemonResponse) task.getChildren().stream().reduce(response, (o, t) -> {
DaemonResponse<U> collector = (DaemonResponse<U>) o;
DaemonTask child = (DaemonTask) t;
DaemonResponse<T> childResponse;
try {
childResponse = task.reapChild(child);
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted("Interrupted during reap", e);
}
DaemonTask.State state = child.getState();
if (!state.isTerminal()) {
throw new IllegalStateException("Child task " + child + " reaped but non-terminal.");
}
switch(state) {
case FAILED:
throw new HalException(childResponse.getProblemSet().getProblems());
case INTERRUPTED:
task.interrupt();
throw new DaemonTaskInterrupted(child.getFatalError());
case TIMED_OUT:
task.timeout();
throw new DaemonTaskInterrupted("Child task timed out");
case SUCCEEDED:
break;
default:
throw new IllegalStateException("Unknown terminal state " + state);
}
collector.getProblemSet().addAll(childResponse.getProblemSet());
collector.setResponseBody(accumulator.apply(collector.getResponseBody(), childResponse.getResponseBody()));
return collector;
}, (Object o1, Object o2) -> {
DaemonResponse<U> r1 = (DaemonResponse<U>) o1;
DaemonResponse<U> r2 = (DaemonResponse<U>) o2;
r1.setResponseBody(combiner.apply(r1.getResponseBody(), r2.getResponseBody()));
r1.getProblemSet().addAll(r2.getProblemSet());
return r1;
});
} else {
throw new IllegalStateException("You must be running a DaemonTask to reduce child tasks");
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class ConfigParser method read.
public <T> T read(Path path, Class<T> tClass) {
try {
InputStream is = new FileInputStream(path.toFile());
Object obj = yamlParser.load(is);
return objectMapper.convertValue(obj, tClass);
} catch (IllegalArgumentException e) {
throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to load " + tClass.getSimpleName() + " config: " + e.getMessage()).build());
} catch (FileNotFoundException e) {
throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to find " + tClass.getSimpleName() + " config: " + e.getMessage()).build());
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class ConfigParser method atomicWrite.
public void atomicWrite(Path path, Object obj) {
String contents = yamlToString(obj);
AtomicFileWriter writer = null;
try {
writer = new AtomicFileWriter(path);
writer.write(contents);
writer.commit();
} catch (IOException ioe) {
ioe.printStackTrace();
throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to write config for profile " + path.toFile().getName() + ": " + ioe.getMessage()).build());
} finally {
if (writer != null) {
writer.close();
}
}
}
Aggregations