use of org.joda.time.Duration in project cloudstack by apache.
the class LibvirtPvlanSetupCommandWrapper method execute.
@Override
public Answer execute(final PvlanSetupCommand command, final LibvirtComputingResource libvirtComputingResource) {
final String primaryPvlan = command.getPrimary();
final String isolatedPvlan = command.getIsolated();
final String pvlanType = "-" + command.getPvlanType();
final String op = command.getOp();
final String dhcpMac = command.getDhcpMac();
final String vmMac = command.getVmMac() == null ? dhcpMac : command.getVmMac();
final String dhcpIp = command.getDhcpIp();
String opr = "-A";
if (op.equals("delete")) {
opr = "-D";
}
String result = null;
final String guestBridgeName = libvirtComputingResource.getGuestBridgeName();
final Duration timeout = libvirtComputingResource.getTimeout();
if (command.getType() == PvlanSetupCommand.Type.DHCP) {
final String ovsPvlanDhcpHostPath = libvirtComputingResource.getOvsPvlanDhcpHostPath();
final Script script = new Script(ovsPvlanDhcpHostPath, timeout, s_logger);
script.add(opr, pvlanType, "-b", guestBridgeName, "-p", primaryPvlan, "-s", isolatedPvlan, "-m", dhcpMac, "-d", dhcpIp);
result = script.execute();
if (result != null) {
s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac);
} else {
s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
}
}
// We run this even for DHCP servers since they're all vms after all
final String ovsPvlanVmPath = libvirtComputingResource.getOvsPvlanVmPath();
final Script script = new Script(ovsPvlanVmPath, timeout, s_logger);
script.add(opr, pvlanType, "-b", guestBridgeName, "-p", primaryPvlan, "-s", isolatedPvlan, "-m", vmMac);
result = script.execute();
if (result != null) {
s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);
return new Answer(command, false, result);
} else {
s_logger.info("Programmed pvlan for vm with mac " + vmMac);
}
return new Answer(command, true, result);
}
use of org.joda.time.Duration in project cloudstack by apache.
the class VirtualRoutingResource method execute.
private Answer execute(AggregationControlCommand cmd) {
Action action = cmd.getAction();
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
assert routerName != null;
assert cmd.getRouterAccessIp() != null;
if (action == Action.Start) {
assert (!_vrAggregateCommandsSet.containsKey(routerName));
Queue<NetworkElementCommand> queue = new LinkedBlockingQueue<>();
_vrAggregateCommandsSet.put(routerName, queue);
return new Answer(cmd, true, "Command aggregation started");
} else if (action == Action.Finish) {
Queue<NetworkElementCommand> queue = _vrAggregateCommandsSet.get(routerName);
int answerCounts = 0;
try {
StringBuilder sb = new StringBuilder();
sb.append("#Apache CloudStack Virtual Router Config File\n");
sb.append("<version>\n" + _cfgVersion + "\n</version>\n");
for (NetworkElementCommand command : queue) {
answerCounts += command.getAnswersCount();
List<ConfigItem> cfg = generateCommandCfg(command);
if (cfg == null) {
s_logger.warn("Unknown commands for VirtualRoutingResource, but continue: " + cmd.toString());
continue;
}
for (ConfigItem c : cfg) {
sb.append(c.getAggregateCommand());
}
}
// TODO replace with applyConfig with a stop on fail
String cfgFileName = "VR-" + UUID.randomUUID().toString() + ".cfg";
FileConfigItem fileConfigItem = new FileConfigItem(VRScripts.CONFIG_CACHE_LOCATION, cfgFileName, sb.toString());
ScriptConfigItem scriptConfigItem = new ScriptConfigItem(VRScripts.VR_CFG, "-c " + VRScripts.CONFIG_CACHE_LOCATION + cfgFileName);
// 120s is the minimal timeout
Duration timeout = _eachTimeout.withDurationAdded(_eachTimeout.getStandardSeconds(), answerCounts);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Aggregate action timeout in seconds is " + timeout.getStandardSeconds());
}
ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), fileConfigItem, timeout);
if (!result.isSuccess()) {
return new Answer(cmd, false, result.getDetails());
}
result = applyConfigToVR(cmd.getRouterAccessIp(), scriptConfigItem, timeout);
if (!result.isSuccess()) {
return new Answer(cmd, false, result.getDetails());
}
return new Answer(cmd, true, "Command aggregation finished");
} finally {
queue.clear();
_vrAggregateCommandsSet.remove(routerName);
}
}
return new Answer(cmd, false, "Fail to recognize aggregation action " + action.toString());
}
use of org.joda.time.Duration in project cloudstack by apache.
the class RollingMaintenanceAgentExecutor method startStageExecution.
@Override
public Pair<Boolean, String> startStageExecution(String stage, File scriptFile, int timeout, String payload) {
checkHooksDirectory();
Duration duration = Duration.standardSeconds(timeout);
final Script script = new Script(scriptFile.getAbsolutePath(), duration, s_logger);
final OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
if (StringUtils.isNotEmpty(payload)) {
script.add(payload);
}
s_logger.info("Executing stage: " + stage + " script: " + script);
output = script.execute(parser) + " " + parser.getLines();
if (script.isTimeout()) {
String msg = "Script " + scriptFile + " timed out";
s_logger.error(msg);
success = false;
return new Pair<>(false, msg);
}
int exitValue = script.getExitValue();
if (exitValue == exitValueTerminatedSignal) {
throw new CloudRuntimeException("Script " + scriptFile + " terminated");
}
success = exitValue == 0 || exitValue == exitValueAvoidMaintenance;
setAvoidMaintenance(exitValue == exitValueAvoidMaintenance);
s_logger.info("Execution finished for stage: " + stage + " script: " + script + ": " + exitValue);
if (s_logger.isDebugEnabled()) {
s_logger.debug(output);
s_logger.debug("Stage " + stage + " execution finished: " + exitValue);
}
return new Pair<>(true, "Stage " + stage + " finished");
}
use of org.joda.time.Duration in project druid by druid-io.
the class JodaUtilsTest method testMinMaxDuration.
@Test
public void testMinMaxDuration() {
final Duration duration = Intervals.ETERNITY.toDuration();
Assert.assertEquals(Long.MAX_VALUE, duration.getMillis());
Assert.assertEquals("PT9223372036854775.807S", duration.toString());
}
use of org.joda.time.Duration in project druid by druid-io.
the class JankyServersTest method testHttpsSilentServer.
@Test
public void testHttpsSilentServer() throws Throwable {
final Lifecycle lifecycle = new Lifecycle();
try {
final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).withSslHandshakeTimeout(new Duration(100)).build();
final HttpClient client = HttpClientInit.createClient(config, lifecycle);
final ListenableFuture<StatusResponseHolder> response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", silentServerSocket.getLocalPort()))), StatusResponseHandler.getInstance());
Throwable e = null;
try {
response.get();
} catch (ExecutionException e1) {
e = e1.getCause();
}
Assert.assertTrue("ChannelException thrown by 'get'", e instanceof ChannelException);
} finally {
lifecycle.stop();
}
}
Aggregations