use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder 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.problem.v1.ProblemBuilder 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();
}
}
}
use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder in project halyard by spinnaker.
the class OrcaRunner method monitor.
private void monitor(Supplier<Pipeline> getPipeline) {
String status;
Pipeline pipeline;
Set<String> loggedTasks = new HashSet<>();
try {
pipeline = getPipeline.get();
status = pipeline.getStatus();
while (status.equalsIgnoreCase("running") || status.equalsIgnoreCase("not_started")) {
logPipelineOutput(pipeline, loggedTasks);
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(10));
pipeline = getPipeline.get();
status = pipeline.getStatus();
}
} catch (RetrofitError e) {
throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to monitor task: " + e.getMessage()).build());
}
logPipelineOutput(pipeline, loggedTasks);
if (status.equalsIgnoreCase("terminal")) {
Problem problem = findExecutionError(pipeline);
throw new HalException(problem);
}
}
use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder in project halyard by spinnaker.
the class VaultServerService method getToken.
public String getToken(String deploymentName, Vault vault) {
String result = "";
InitStatus initStatus;
try {
initStatus = vault.initStatus();
} catch (RetrofitError e) {
throw handleVaultError(e, "check init status");
}
if (!initStatus.isInitialized()) {
try {
InitResponse init = vault.init(new InitRequest().setSecretShares(3).setSecretThreshold(3));
result = init.getRootToken();
for (String key : init.getKeys()) {
vault.unseal(new UnsealRequest().setKey(key));
}
} catch (RetrofitError e) {
throw handleVaultError(e, "init vault");
}
}
SealStatus sealStatus;
try {
sealStatus = vault.sealStatus();
} catch (RetrofitError e) {
throw handleVaultError(e, "check seal status");
}
if (sealStatus.isSealed()) {
throw new HalException(Problem.Severity.FATAL, "Your vault is in a sealed state, no config can be written.");
}
File vaultTokenFile = halconfigDirectoryStructure.getVaultTokenPath(deploymentName).toFile();
if (result.isEmpty()) {
try {
result = IOUtils.toString(new FileInputStream(vaultTokenFile));
} catch (IOException e) {
throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Unable to read vault token: " + e.getMessage()).setRemediation("This file is needed for storing credentials to your vault server. " + "If you have deployed vault by hand, make sure Halyard can authenticate using the token in that file.").build());
}
} else {
try {
IOUtils.write(result.getBytes(), new FileOutputStream(vaultTokenFile));
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Unable to write vault token: " + e.getMessage());
}
}
return result;
}
use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder in project halyard by spinnaker.
the class DistributedDeployer method deploy.
@Override
public RemoteAction deploy(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, ResolvedConfiguration resolvedConfiguration, List<SpinnakerService.Type> serviceTypes) {
SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
DaemonTaskHandler.newStage("Deploying Spinnaker");
// First deploy all services not owned by Spinnaker
for (DistributedService distributedService : serviceProvider.getPrioritizedDistributedServices(serviceTypes)) {
SpinnakerService service = distributedService.getService();
ServiceSettings settings = resolvedConfiguration.getServiceSettings(service);
if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) {
continue;
}
DaemonTaskHandler.newStage("Determining status of " + distributedService.getServiceName());
boolean safeToUpdate = settings.getSafeToUpdate();
RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(deploymentDetails, runtimeSettings);
if (distributedService.isRequiredToBootstrap() || !safeToUpdate) {
deployServiceManually(deploymentDetails, resolvedConfiguration, distributedService, safeToUpdate);
} else {
DaemonResponse.StaticRequestBuilder<Void> builder = new DaemonResponse.StaticRequestBuilder<>(() -> {
if (runningServiceDetails.getLatestEnabledVersion() == null) {
DaemonTaskHandler.newStage("Deploying " + distributedService.getServiceName() + " via provider API");
deployServiceManually(deploymentDetails, resolvedConfiguration, distributedService, safeToUpdate);
} else {
DaemonTaskHandler.newStage("Deploying " + distributedService.getServiceName() + " via red/black");
Orca orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA_BOOTSTRAP, Orca.class).connectToPrimaryService(deploymentDetails, runtimeSettings);
deployServiceWithOrca(deploymentDetails, resolvedConfiguration, orca, distributedService);
}
return null;
});
DaemonTaskHandler.submitTask(builder::build, "Deploy " + distributedService.getServiceName());
}
}
DaemonTaskHandler.message("Waiting on deployments to complete");
DaemonTaskHandler.reduceChildren(null, (t1, t2) -> null, (t1, t2) -> null).getProblemSet().throwifSeverityExceeds(Problem.Severity.WARNING);
DistributedService<Orca, T> orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA);
Set<Integer> unknownVersions = reapOrcaServerGroups(deploymentDetails, runtimeSettings, orca);
reapRoscoServerGroups(deploymentDetails, runtimeSettings, serviceProvider.getDeployableService(SpinnakerService.Type.ROSCO));
if (!unknownVersions.isEmpty()) {
String versions = String.join(", ", unknownVersions.stream().map(orca::getVersionedName).collect(Collectors.toList()));
throw new HalException(new ProblemBuilder(Problem.Severity.ERROR, "The following orca versions (" + versions + ") could not safely be drained of work.").setRemediation("Please make sure that no pipelines are running, and manually destroy the server groups at those versions.").build());
}
return new RemoteAction();
}
Aggregations