use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class ClusterService method deleteCluster.
public void deleteCluster(String deploymentName, String providerName, String clusterName) {
final HasClustersProvider clustersProvider = providerService.getHasClustersProvider(deploymentName, providerName);
final List<Cluster> clusters = (List<Cluster>) clustersProvider.getClusters();
boolean removed = clusters.removeIf(cluster -> cluster.getName().equals(clusterName));
if (!removed) {
throw new HalException(Problem.Severity.FATAL, "Cluster \"" + clusterName + "\" wasn't found");
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class RemoteAction method commitScript.
public void commitScript(Path path) {
AtomicFileWriter writer = null;
try {
writer = new AtomicFileWriter(path);
writer.write(script);
writer.commit();
} catch (IOException ioe) {
ioe.printStackTrace();
throw new HalException(Problem.Severity.FATAL, "Failed to write config for profile " + path.toFile().getName() + ": " + ioe.getMessage());
} finally {
if (writer != null) {
writer.close();
}
}
path.toFile().setExecutable(true);
scriptPath = path.toString();
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class CanaryAccountService method deleteAccount.
public void deleteAccount(String deploymentName, String serviceIntegrationName, String accountName) {
AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName);
boolean removed = serviceIntegration.getAccounts().removeIf(account -> ((AbstractCanaryAccount) account).getName().equals(accountName));
if (!removed) {
throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Canary account \"" + accountName + "\" wasn't found").build());
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class MasterService method deleteMaster.
public void deleteMaster(String deploymentName, String ciName, String masterName) {
Ci ci = ciService.getCi(deploymentName, ciName);
boolean removed = ci.getMasters().removeIf(master -> ((Master) master).getName().equals(masterName));
if (!removed) {
throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Master \"" + masterName + "\" wasn't found").build());
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException 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);
}
}
Aggregations