Search in sources :

Example 56 with Duration

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);
}
Also used : Script(com.cloud.utils.script.Script) Answer(com.cloud.agent.api.Answer) Duration(org.joda.time.Duration)

Example 57 with Duration

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());
}
Also used : Action(com.cloud.agent.api.routing.AggregationControlCommand.Action) Duration(org.joda.time.Duration) ExecutionResult(com.cloud.utils.ExecutionResult) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) SetupKeystoreAnswer(org.apache.cloudstack.ca.SetupKeystoreAnswer) Answer(com.cloud.agent.api.Answer) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer) DiagnosticsAnswer(org.apache.cloudstack.diagnostics.DiagnosticsAnswer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) PrepareFilesAnswer(org.apache.cloudstack.diagnostics.PrepareFilesAnswer) ArrayList(java.util.ArrayList) List(java.util.List) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Queue(java.util.Queue)

Example 58 with Duration

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");
}
Also used : Script(com.cloud.utils.script.Script) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Duration(org.joda.time.Duration) OutputInterpreter(com.cloud.utils.script.OutputInterpreter) Pair(com.cloud.utils.Pair)

Example 59 with Duration

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());
}
Also used : Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 60 with Duration

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();
    }
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) Duration(org.joda.time.Duration) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) ChannelException(org.jboss.netty.channel.ChannelException) Test(org.junit.Test)

Aggregations

Duration (org.joda.time.Duration)272 Test (org.junit.Test)148 Instant (org.joda.time.Instant)66 DateTime (org.joda.time.DateTime)32 Period (org.joda.time.Period)27 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)24 TestDruidCoordinatorConfig (org.apache.druid.server.coordinator.TestDruidCoordinatorConfig)22 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Category (org.junit.experimental.categories.Category)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 KV (org.apache.beam.sdk.values.KV)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 IndexSpec (org.apache.druid.segment.IndexSpec)12 Set (java.util.Set)10 GlobalWindows (org.apache.beam.sdk.transforms.windowing.GlobalWindows)10 DynamicPartitionsSpec (org.apache.druid.indexer.partitions.DynamicPartitionsSpec)10 Interval (org.joda.time.Interval)10 Request (com.metamx.http.client.Request)9