use of com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL in project halyard by spinnaker.
the class HalconfigParser method cleanLocalFiles.
/**
* Deletes all files in the staging directory that are not referenced in the hal config.
*/
public void cleanLocalFiles(Path stagingDirectoryPath) {
if (!GlobalApplicationOptions.getInstance().isUseRemoteDaemon()) {
return;
}
Halconfig halconfig = getHalconfig();
Set<String> referencedFiles = new HashSet<String>();
Consumer<Node> fileFinder = n -> referencedFiles.addAll(n.localFiles().stream().map(f -> {
try {
f.setAccessible(true);
return (String) f.get(n);
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to clean staging directory: " + e.getMessage(), e);
} finally {
f.setAccessible(false);
}
}).filter(Objects::nonNull).collect(Collectors.toSet()));
halconfig.recursiveConsume(fileFinder);
Set<String> existingStagingFiles = ((List<File>) FileUtils.listFiles(stagingDirectoryPath.toFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)).stream().map(f -> f.getAbsolutePath()).collect(Collectors.toSet());
existingStagingFiles.removeAll(referencedFiles);
try {
for (String f : existingStagingFiles) {
FileUtils.forceDelete(new File(f));
}
} catch (IOException e) {
throw new HalException(FATAL, "Failed to clean staging directory: " + e.getMessage(), e);
}
}
use of com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL in project halyard by spinnaker.
the class ResponseUnwrapper method formatProblemSet.
private static void formatProblemSet(ProblemSet problemSet) {
if (problemSet == null || problemSet.isEmpty()) {
return;
}
AnsiSnippet snippet = new AnsiSnippet("\r").setErase(AnsiErase.ERASE_LINE);
AnsiPrinter.err.print(snippet.toString());
Map<String, List<Problem>> locationGroup = problemSet.groupByLocation();
for (Entry<String, List<Problem>> entry : locationGroup.entrySet()) {
AnsiUi.problemLocation(entry.getKey());
for (Problem problem : entry.getValue()) {
Severity severity = problem.getSeverity();
String message = problem.getMessage();
String remediation = problem.getRemediation();
List<String> options = problem.getOptions();
switch(severity) {
case FATAL:
case ERROR:
AnsiUi.error(message);
break;
case WARNING:
AnsiUi.warning(message);
break;
default:
throw new RuntimeException("Unknown severity level " + severity);
}
if (remediation != null && !remediation.isEmpty()) {
AnsiUi.remediation(remediation);
}
if (options != null && !options.isEmpty()) {
AnsiUi.remediation("Options include: ");
options.forEach(AnsiUi::listRemediation);
}
// Newline between errors
AnsiUi.raw("");
}
}
}
use of com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL in project halyard by spinnaker.
the class GoogleDistributedService method getRunningServiceDetails.
@Override
default RunningServiceDetails getRunningServiceDetails(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
RunningServiceDetails result = new RunningServiceDetails();
// All GCE load balancing is done via consul
result.setLoadBalancer(new RunningServiceDetails.LoadBalancer().setExists(true));
Compute compute = GoogleProviderUtils.getCompute(details);
GoogleAccount account = details.getAccount();
List<InstanceGroupManager> migs;
try {
migs = compute.instanceGroupManagers().list(account.getProject(), settings.getLocation()).execute().getItems();
if (migs == null) {
migs = Collections.emptyList();
}
} catch (IOException e) {
throw new HalException(FATAL, "Failed to load MIGS: " + e.getMessage(), e);
}
boolean consulEnabled = getSidecars(runtimeSettings).stream().anyMatch(s -> s.getService().getType().equals(SpinnakerService.Type.CONSUL_CLIENT));
Set<String> healthyConsulInstances = consulEnabled ? getConsulServerService().connectToPrimaryService(details, runtimeSettings).serviceHealth(getService().getCanonicalName(), true).stream().map(s -> s != null && s.getNode() != null ? s.getNode().getNodeName() : null).filter(Objects::nonNull).collect(Collectors.toSet()) : new HashSet<>();
String serviceName = getService().getServiceName();
migs = migs.stream().filter(ig -> ig.getName().startsWith(serviceName + "-v")).collect(Collectors.toList());
Map<Integer, List<RunningServiceDetails.Instance>> instances = migs.stream().reduce(new HashMap<>(), (map, mig) -> {
Names names = Names.parseName(mig.getName());
Integer version = names.getSequence();
List<RunningServiceDetails.Instance> computeInstances;
try {
List<ManagedInstance> managedInstances = compute.instanceGroupManagers().listManagedInstances(account.getProject(), settings.getLocation(), mig.getName()).execute().getManagedInstances();
if (managedInstances == null) {
managedInstances = new ArrayList<>();
}
computeInstances = managedInstances.stream().map(i -> {
String instanceUrl = i.getInstance();
String instanceStatus = i.getInstanceStatus();
boolean running = instanceStatus != null && instanceStatus.equalsIgnoreCase("running");
String instanceName = instanceUrl.substring(instanceUrl.lastIndexOf('/') + 1, instanceUrl.length());
return new RunningServiceDetails.Instance().setId(instanceName).setLocation(settings.getLocation()).setRunning(running).setHealthy(!consulEnabled || healthyConsulInstances.contains(instanceName));
}).collect(Collectors.toList());
} catch (IOException e) {
throw new HalException(FATAL, "Failed to load target pools for " + serviceName, e);
}
map.put(version, computeInstances);
return map;
}, (m1, m2) -> {
m1.putAll(m2);
return m1;
});
result.setInstances(instances);
return result;
}
use of com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL in project halyard by spinnaker.
the class Node method backupLocalFiles.
public List<String> backupLocalFiles(String outputPath) {
List<String> files = new ArrayList<>();
Consumer<Node> fileFinder = n -> files.addAll(n.localFiles().stream().map(f -> {
try {
f.setAccessible(true);
String fPath = (String) f.get(n);
if (fPath == null) {
return null;
}
File fFile = new File(fPath);
String fName = fFile.getName();
// Hash the path to uniquely flatten all files into the output directory
Path newName = Paths.get(outputPath, Math.abs(fPath.hashCode()) + "-" + fName);
File parent = newName.toFile().getParentFile();
if (!parent.exists()) {
parent.mkdirs();
} else if (fFile.getParent().equals(parent.toString())) {
// Don't move paths that are already in the right folder
return fPath;
}
Files.copy(Paths.get(fPath), newName, REPLACE_EXISTING);
f.set(n, newName.toString());
return newName.toString();
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e);
} catch (IOException e) {
throw new HalException(FATAL, "Failed to backup user file: " + e.getMessage(), e);
} finally {
f.setAccessible(false);
}
}).filter(Objects::nonNull).collect(Collectors.toList()));
recursiveConsume(fileFinder);
return files;
}
Aggregations