use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class OperationQueueBase method createExecution.
protected JobExecutionData createExecution(JobData jobData) throws OpsException {
Date startedAt = new Date();
String executionId;
try {
executionId = jobRepository.insertExecution(jobData.key, startedAt);
} catch (RepositoryException e) {
throw new OpsException("Error inserting job execution into repository", e);
}
JobExecutionData execution = new JobExecutionData();
execution.job = jobData;
execution.jobKey = jobData.getJobKey();
execution.startedAt = startedAt;
execution.executionId = executionId;
execution.state = JobState.PRESTART;
return execution;
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class PersistentJobRegistry method getJobLog.
// @Override
// JobRecord startJob(JobRecord jobRecord) {
// PlatformLayerKey jobKey = jobRecord.getJobKey();
//
// if (jobKey != null) {
// synchronized (activeJobs) {
// activeJobs.put(jobKey, jobRecord);
// }
// }
//
// return jobRecord;
// }
// public JobData getJob(PlatformLayerKey jobKey, boolean fetchLog) {
// JobData jobData = null;
// synchronized (activeJobs) {
// jobRecord = activeJobs.get(jobKey);
// }
//
// if (jobData == null) {
// synchronized (recentJobs) {
// for (JobData recentJob : recentJobs) {
// if (recentJob.getJobKey().equals(jobKey)) {
// jobData = recentJob;
// break;
// }
// }
// }
// }
//
// if (jobData == null) {
// throw new UnsupportedOperationException();
//
// // jobRecord = repository.getJob(jobId, fetchLog);
// }
//
// return jobData;
// }
@Override
public JobLog getJobLog(PlatformLayerKey jobKey, String executionId, int logSkip) throws OpsException {
JobExecutionData execution = findExecution(jobKey, executionId);
Date startedAt = execution.getStartedAt();
if (execution.getEndedAt() == null) {
JobLog log = operationQueue.getActiveJobLog(jobKey, executionId);
if (log != null) {
JobLog ret = new JobLog();
ret.lines = Lists.newArrayList(Iterables.skip(log.lines, logSkip));
ret.execution = log.execution;
return ret;
}
}
try {
String cookie = execution.logCookie;
JobLog log = jobLogStore.getJobLog(startedAt, jobKey, executionId, cookie, logSkip);
if (log != null) {
log.execution = execution;
}
return log;
} catch (IOException e) {
throw new OpsException("Error reading job log", e);
}
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class AptPackageManager method getInstalledPackageInfo.
public List<String> getInstalledPackageInfo(OpsTarget target) throws OpsException {
AptInfoCache cached = getCache(target);
if (cached.installedPackages == null) {
Command command = Command.build("/usr/bin/dpkg --get-selections");
ProcessExecution execution = target.executeCommand(command);
final List<String> packages = Lists.newArrayList();
for (String line : Splitter.on("\n").split(execution.getStdOut())) {
line = line.trim();
if (line.isEmpty()) {
continue;
}
List<String> tokens = Lists.newArrayList(Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings().split(line));
if (tokens.size() != 2) {
throw new OpsException("Error parsing line; expected 2 items: " + line);
}
String state = tokens.get(1);
if (state.equals("install")) {
String packageName = tokens.get(0);
int colonIndex = packageName.indexOf(':');
if (colonIndex != -1) {
// Architecture sometimes follows package name
packageName = packageName.substring(0, colonIndex);
}
packages.add(packageName);
} else if (state.equals("deinstall")) {
// Not installed (?)
} else {
throw new OpsException("Unknown package state in line: " + line);
}
}
cached.installedPackages = packages;
} else {
log.debug("Re-using cached package info");
}
return cached.installedPackages;
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class FilesystemBackedPool method release.
@Override
public void release(PlatformLayerKey owner, T item) throws OpsException {
File symlink = new File(assignedDir, toKey(item));
FilesystemInfo info = target.getFilesystemInfoFile(symlink);
if (info == null) {
throw new OpsException("Symlink not found");
}
if (!Objects.equal(info.symlinkTarget, toFile(owner).getAbsolutePath())) {
throw new OpsException("Resource not assigned to owner");
}
target.rm(symlink);
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class IpsecHelpers method getIpsecSecret.
public Secret getIpsecSecret() throws OpsException {
Secret secret = null;
for (ProviderOf<HasIpsecPolicy> ipsecPolicyProvider : providerHelper.listItemsProviding(HasIpsecPolicy.class)) {
ItemBase item = ipsecPolicyProvider.getItem();
if (item.getState() != ManagedItemState.ACTIVE) {
continue;
}
HasIpsecPolicy ipsec = ipsecPolicyProvider.get();
if (secret != null) {
throw new IllegalStateException("Multiple IPSEC policies found");
}
secret = ipsec.getIpsecPreSharedKey(item);
if (secret == null) {
// Should we allow this?
throw new IllegalStateException();
}
}
if (secret == null) {
throw new OpsException("Ipsec policy not found");
}
return secret;
}
Aggregations