コード例 #1
0
 public static ModifyServiceResponseType modifyService(final ModifyServiceType request)
     throws Exception {
   final ModifyServiceResponseType reply = request.getReply();
   try {
     if (NamedTransition.INSTANCE.apply(request)) {
       reply.markWinning();
     } else {
       Component.State nextState = Component.State.valueOf(request.getState().toUpperCase());
       ServiceConfiguration config = findService(request.getName());
       Topology.transition(nextState).apply(config).get();
       reply.markWinning();
     }
   } catch (Exception ex) {
     Exceptions.maybeInterrupted(ex);
     throw new EucalyptusCloudException(
         "Failed to execute request transition: "
             + request.getState()
             + "\nDue to:\n"
             + Throwables.getRootCause(ex).getMessage()
             + "\nPossible arguments are: \n"
             + "TRANSITIONS\n\t"
             + Joiner.on("\n\t").join(Topology.Transitions.values())
             + "STATES\n\t"
             + Joiner.on("\n\t").join(Component.State.values()),
         ex);
   }
   return reply;
 }
コード例 #2
0
    @Override
    public boolean apply(ModifyServiceType request) {
      try {
        final Topology.Transitions transition =
            Topology.Transitions.valueOf(request.getState().toUpperCase());
        String name = request.getName();
        ServiceConfiguration config = findService(name);
        if (Topology.Transitions.RESTART.equals(transition)) {
          Topology.stop(config).get();
          try {
            Topology.start(config).get();
          } catch (Exception ex) {
            Exceptions.maybeInterrupted(ex);
            Logs.extreme().error(ex, ex);
            throw Exceptions.toUndeclared(ex);
          }
        } else {
          Topology.transition(transition.get()).apply(config).get();
        }
      } catch (final IllegalArgumentException ex) {
        return false;
      } catch (final Exception ex) {
        Exceptions.maybeInterrupted(ex);
        Logs.extreme().error(ex, ex);
        throw Exceptions.toUndeclared(ex);
      }

      return true;
    }