Skip to content

Instantly share code, notes, and snippets.

@yaronp68
Created March 15, 2012 09:10

Revisions

  1. yaronp68 created this gist Mar 15, 2012.
    36 changes: 36 additions & 0 deletions stopManagement.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    @Override
    public void stopManagementMachines()
    throws TimeoutException, CloudProvisioningException {
    final String token = createAuthenticationToken();

    final long endTime = calcEndTimeInMillis(
    DEFAULT_SHUTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    List<Node> nodes;
    try {
    nodes = listServers(token);
    } catch (final OpenstackException e) {
    throw new CloudProvisioningException(e);
    }

    final List<String> ids = new LinkedList<String>();
    for (final Node node : nodes) {
    if (node.getName().startsWith(
    this.serverNamePrefix)) {
    try {
    ids.add(node.getId());

    } catch (final Exception e) {
    throw new CloudProvisioningException(e);
    }
    }
    }

    try {
    terminateServers(
    ids, token, endTime);
    } catch (final TimeoutException e) {
    throw e;
    } catch (final Exception e) {
    throw new CloudProvisioningException("Failed to shut down managememnt machines", e);
    }
    }