use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class NetworkPoint method forMe.
public static NetworkPoint forMe() throws OpsException {
if (myAddress == null) {
List<InetAddress> localAddresses = InetAddressUtils.getLocalAddresses();
List<InetAddress> valid = Lists.newArrayList();
for (InetAddress localAddress : localAddresses) {
if (InetAddressUtils.isIpv4(localAddress)) {
continue;
}
if (localAddress.isLinkLocalAddress()) {
continue;
}
if (localAddress.isLoopbackAddress()) {
continue;
}
valid.add(localAddress);
}
InetAddress address = InetAddressChooser.preferIpv6().choose(valid);
if (!InetAddressUtils.isIpv6(address)) {
throw new OpsException("We must have an IPV6 address");
}
myAddress = address;
}
return new NetworkPoint(null, myAddress);
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class NetworkPoints method resolveAll.
public List<NetworkPoint> resolveAll(List<? extends ItemBase> items, boolean ignoreErrors) throws OpsException {
List<NetworkPoint> points = Lists.newArrayList();
for (ItemBase item : items) {
NetworkPoint point = findNetworkPoint(item);
if (point == null) {
if (ignoreErrors) {
log.debug("Ignoring unresolvable item");
} else {
throw new OpsException("Unable to resolve item: " + item.getKey());
}
}
points.add(point);
}
return points;
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class IpsecPresharedKey method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
if (OpsContext.isConfigure()) {
File pskFile = new File("/etc/racoon/psk.txt");
String psk = target.readTextFile(pskFile);
if (psk == null) {
psk = "# Managed by PlatformLayer\n";
}
boolean found = false;
// TODO: Extend MapSplitter / add some helper functions??
Splitter keyValueSpliter = Splitter.on(CharMatcher.WHITESPACE).limit(2).omitEmptyStrings().trimResults();
Map<String, String> psks = Maps.newHashMap();
for (String line : Splitter.on("\n").trimResults().omitEmptyStrings().split(psk)) {
if (line.startsWith("#")) {
continue;
}
List<String> tokens = Lists.newArrayList(keyValueSpliter.split(line));
if (tokens.size() != 2) {
throw new OpsException("Cannot parse PSK line: " + line);
}
String key = tokens.get(0);
String value = tokens.get(1);
if (psks.containsKey(key)) {
// (We could check to see if they're the same, but this is generally not good)
throw new OpsException("Found duplicate PSK");
}
psks.put(key, value);
if (!key.equals(id)) {
continue;
}
if (value.equals(secret.plaintext())) {
found = true;
}
}
if (!found) {
psk = psk + "\n";
psk += id + " " + secret.plaintext() + "\n";
FileUpload.upload(target, pskFile, psk);
target.executeCommand(Command.build("racoonctl reload-config"));
}
}
}
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);
}
}
Aggregations