use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException in project cloudconductor-agent-redhat by cinovo.
the class ServerCom method notifyRunningServices.
/**
* @param req the service update req
* @return the response
* @throws CloudConductorException thrown if communication with cloudconductor failed
*/
public static ServiceStatesChanges notifyRunningServices(ServiceStates req) throws CloudConductorException {
try {
String template = AgentState.info().getTemplate();
String host = AgentState.info().getHost();
String uuid = AgentState.info().getUuid();
return ServerCom.agent.notifyServiceState(template, host, req, uuid);
} catch (RuntimeException e) {
throw new CloudConductorException(e.getMessage());
}
}
use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException in project cloudconductor-agent-redhat by cinovo.
the class ServerCom method notifyInstalledPackages.
/**
* @param installedPackages the installed packages
* @return the response
* @throws CloudConductorException thrown if communication with cloudconductor failed
*/
public static PackageStateChanges notifyInstalledPackages(PackageState installedPackages) throws CloudConductorException {
try {
String template = AgentState.info().getTemplate();
String host = AgentState.info().getHost();
String uuid = AgentState.info().getUuid();
return ServerCom.agent.notifyPackageState(template, host, installedPackages, uuid);
} catch (RuntimeException e) {
throw new CloudConductorException(e.getMessage());
}
}
use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException in project cloudconductor-agent-redhat by cinovo.
the class FilesJob method run.
@Override
public void run() {
FilesJob.LOGGER.debug("Started FilesJob");
// only run if no other blocking job is currently running
if (AgentState.filesExecutionLock.tryLock()) {
try {
new ConfigFileHandler().run();
} catch (ExecutionError e) {
if (e.getCause() instanceof CloudConductorException) {
FilesJob.LOGGER.debug(e.getMessage(), e);
}
} finally {
AgentState.filesExecutionLock.unlock();
}
}
FilesJob.LOGGER.debug("Finished FilesJob");
}
use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException in project cloudconductor-agent-redhat by cinovo.
the class NodeAgent method checkServer.
private boolean checkServer() throws ServerConnectionException {
NodeAgent.LOGGER.info("Perform first authentication...");
new RefreshJWTJob().run();
NodeAgent.LOGGER.info("Get template from server...");
try {
Template template = ServerCom.getTemplate();
if (template != null) {
return true;
}
throw new ServerConnectionException();
} catch (CloudConductorException e) {
NodeAgent.LOGGER.error("Error getting template from server: ", e);
throw new ServerConnectionException();
}
}
use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException in project cloudconductor-agent-redhat by cinovo.
the class FileExecutor method execute.
@Override
public IExecutor<Set<String>> execute() throws ExecutionError {
this.errors = new StringBuilder();
for (ConfigFile configFile : this.files) {
boolean changeOccured = false;
if (configFile.isDirectory()) {
File dirs = new File(configFile.getTargetPath());
String dirMode = configFile.getFileMode();
if (!dirs.exists()) {
// create missing directories
if (dirs.mkdirs()) {
changeOccured = true;
this.checkDirPermOwner(dirs, dirMode, configFile.getOwner(), configFile.getGroup());
}
} else {
changeOccured = this.checkDirPermOwner(dirs, dirMode, configFile.getOwner(), configFile.getGroup());
}
} else {
// in case config file is a file
File localFile = new File(configFile.getTargetPath());
HashCode localFileHash = FileHelper.getChecksum(localFile);
String serverFile;
try {
serverFile = ServerCom.getFileData(configFile);
} catch (TransformationErrorException | CloudConductorException e) {
FileExecutor.LOGGER.error("Error getting file data for config file '" + configFile.getName() + "': ", e);
continue;
}
HashCode serverFileHash = FileHelper.getChecksum(serverFile);
if (!serverFileHash.equals(localFileHash)) {
try {
FileExecutor.LOGGER.debug("Update config file '" + configFile.getName() + "'...");
Files.createParentDirs(localFile);
Files.write(serverFile, localFile, Charset.forName("UTF-8"));
changeOccured = true;
} catch (IOException e) {
// add error to exception list
this.errors.append("Failed to write file: " + localFile.getAbsolutePath());
this.errors.append(System.lineSeparator());
// just skip this file
continue;
}
}
// set file owner and group
try {
if (!FileHelper.isFileOwner(localFile, configFile.getOwner(), configFile.getGroup())) {
FileHelper.chown(localFile, configFile.getOwner(), configFile.getGroup());
changeOccured = true;
}
} catch (IOException e) {
this.errors.append("Failed to set user and/or group for file: " + localFile.getAbsolutePath());
this.errors.append(System.lineSeparator());
}
// set file mode
try {
String fileMode = FileHelper.fileModeIntToString(ServerCom.getFileMode(configFile.getName()));
if (!FileHelper.isFileMode(localFile, fileMode)) {
FileHelper.chmod(localFile, fileMode);
changeOccured = true;
}
} catch (IOException e) {
this.errors.append("Failed to set chmod for file: " + localFile.getAbsolutePath());
this.errors.append(System.lineSeparator());
} catch (CloudConductorException e) {
this.errors.append(e.getMessage());
this.errors.append(System.lineSeparator());
}
}
// set services to restart
if (configFile.isReloadable() && changeOccured) {
Set<String> servicesToRestart = configFile.getDependentServices();
this.restart.addAll(servicesToRestart);
FileExecutor.LOGGER.debug("Config file changed, " + servicesToRestart.size() + " services have to be restarted!");
}
}
if (!this.errors.toString().trim().isEmpty()) {
throw new ExecutionError(this.errors.toString().trim());
}
return this;
}
Aggregations