use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class HalconfigParser method saveConfigTo.
private void saveConfigTo(Path path) {
Halconfig local = (Halconfig) DaemonTaskHandler.getContext();
if (local == null) {
throw new HalException(new ConfigProblemBuilder(Severity.WARNING, "No halconfig changes have been made, nothing to write").build());
}
AtomicFileWriter writer = null;
try {
writer = new AtomicFileWriter(path);
writer.write(yamlParser.dump(objectMapper.convertValue(local, Map.class)));
writer.commit();
} catch (IOException e) {
throw new HalException(Severity.FATAL, "Failure writing your halconfig to path \"" + halconfigPath + "\": " + e.getMessage(), e);
} finally {
DaemonTaskHandler.setContext(null);
if (writer != null) {
writer.close();
}
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class SubscriptionService method deleteSubscription.
public void deleteSubscription(String deploymentName, String pubsubName, String subscriptionName) {
Pubsub pubsub = pubsubService.getPubsub(deploymentName, pubsubName);
boolean removed = pubsub.getSubscriptions().removeIf(subscription -> ((Subscription) subscription).getName().equals(subscriptionName));
if (!removed) {
throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Subscription \"" + subscriptionName + "\" wasn't found").build());
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException 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