public static void handle(String service, MuleMessage responseMessage, BaseMessage request) {
   BaseMessage reply = null;
   if (responseMessage.getExceptionPayload() == null) {
     reply = (BaseMessage) responseMessage.getPayload();
   } else {
     Throwable t = responseMessage.getExceptionPayload().getException();
     t = (t.getCause() == null) ? t : t.getCause();
     reply = new EucalyptusErrorMessageType(service, request, t.getMessage());
   }
   String corrId = reply.getCorrelationId();
   EventRecord.here(
           EuareReplyQueue.class,
           EventType.MSG_REPLY,
           reply.getCorrelationId(),
           reply.getClass().getSimpleName())
       .debug();
   try {
     Context context = Contexts.lookup(corrId);
     Channel channel = context.getChannel();
     Channels.write(channel, reply);
     Contexts.clear(context);
   } catch (NoSuchContextException e) {
     LOG.trace(e, e);
   }
 }
Exemplo n.º 2
0
 public static void processFiles() {
   final File libDir = new File(BaseDirectory.LIB.toString());
   for (final File f : libDir.listFiles()) {
     if (f.getName().startsWith("eucalyptus")
         && f.getName().endsWith(".jar")
         && !f.getName().matches(".*-ext-.*")) {
       EventRecord.here(
               ServiceJarDiscovery.class, EventType.BOOTSTRAP_INIT_SERVICE_JAR, f.getName())
           .info();
       try {
         BindingFileSearch.INSTANCE.process(f);
       } catch (final Throwable e) {
         LOG.error(e.getMessage());
         continue;
       }
     }
   }
   for (String pathName : ClassPath.SYSTEM_CLASS_PATH.getClassPath().split(File.pathSeparator)) {
     File pathFile = new File(pathName);
     if (pathFile.isDirectory()) {
       try {
         BindingFileSearch.INSTANCE.process(pathFile);
       } catch (final Throwable e) {
         LOG.error(e.getMessage());
         continue;
       }
       ;
     }
   }
 }
Exemplo n.º 3
0
 @Override
 public void fireEnable(ServiceConfiguration config) throws ServiceRegistrationException {
   if (!config.isVmLocal()) {
     for (Host h : Hosts.list()) {
       if (h.getHostAddresses().contains(config.getInetAddress())) {
         EventRecord.here(
                 EucalyptusBuilder.class, EventType.COMPONENT_SERVICE_ENABLED, config.toString())
             .info();
         return;
       }
     }
     throw Faults.failure(
         config,
         Exceptions.error(
             "There is no host in the system (yet) for the given cloud controller configuration: "
                 + config.getFullName()
                 + ".\nHosts are: "
                 + Hosts.list()));
   } else if (config.isVmLocal() && !Hosts.isCoordinator()) {
     throw Faults.failure(
         config,
         Exceptions.error(
             "This cloud controller "
                 + config.getFullName()
                 + " is not currently the coordinator "
                 + Hosts.list()));
   }
 }
 @Override
 public void fireCheck(ServiceConfiguration config) throws ServiceRegistrationException {
   EventRecord.here(
           ServiceBuilder.class,
           EventType.COMPONENT_SERVICE_CHECK,
           config.getFullName().toString(),
           config.toString())
       .exhaust();
 }
Exemplo n.º 5
0
 public <T extends ServiceConfiguration> T remove(final T config) {
   final EntityTransaction db = Entities.get(config.getClass());
   try {
     final T searchConfig = (T) config.getClass().newInstance();
     searchConfig.setName(config.getName());
     final T exists = Entities.uniqueResult(searchConfig);
     Entities.delete(exists);
     db.commit();
     EventRecord.here(
             ServiceConfigurations.class,
             EventClass.COMPONENT,
             EventType.COMPONENT_DEREGISTERED,
             config.toString())
         .info();
   } catch (final NoSuchElementException ex) {
     db.rollback();
   } catch (final PersistenceException ex) {
     LOG.debug(ex);
     EventRecord.here(
             ServiceConfigurations.class,
             EventClass.COMPONENT,
             EventType.COMPONENT_DEREGISTERED,
             "FAILED",
             config.toString())
         .error();
     db.rollback();
     throw ex;
   } catch (final Throwable ex) {
     LOG.debug(ex);
     EventRecord.here(
             ServiceConfigurations.class,
             EventClass.COMPONENT,
             EventType.COMPONENT_DEREGISTERED,
             "FAILED",
             config.toString())
         .error();
     db.rollback();
     throw new PersistenceException(
         "Service configuration removal failed for: " + LogUtil.dumpObject(config), ex);
   }
   return config;
 }
Exemplo n.º 6
0
 public <T extends ServiceConfiguration> T store(T config) {
   final EntityTransaction db = Entities.get(config.getClass());
   try {
     config = Entities.persist(config);
     db.commit();
     EventRecord.here(
             ServiceConfigurations.class,
             EventClass.COMPONENT,
             EventType.COMPONENT_REGISTERED,
             config.toString())
         .info();
   } catch (final PersistenceException ex) {
     LOG.debug(ex);
     EventRecord.here(
             ServiceConfigurations.class,
             EventClass.COMPONENT,
             EventType.COMPONENT_REGISTERED,
             "FAILED",
             config.toString())
         .error();
     db.rollback();
     throw ex;
   } catch (final Throwable ex) {
     LOG.debug(ex);
     EventRecord.here(
             ServiceConfigurations.class,
             EventClass.COMPONENT,
             EventType.COMPONENT_REGISTERED,
             "FAILED",
             config.toString())
         .error();
     db.rollback();
     throw new PersistenceException(
         "Service configuration storing failed for: " + LogUtil.dumpObject(config), ex);
   }
   return config;
 }
 @Override
 public void fire(AssignAddressResponseType msg) {
   try {
     if (!this.checkVmState()) {
       this.clearState();
     } else {
       this.address.clearPending();
       EventRecord.here(
               AssignAddressCallback.class,
               EventType.ADDRESS_ASSIGNED,
               Address.State.assigned.toString(),
               this.address.toString())
           .info();
     }
   } catch (Exception e) {
     LOG.debug(e, e);
     this.clearState();
   }
 }
 @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
 public void handle(final ExceptionMessage exMsg) {
   EventRecord.here(getClass(), EventType.MSG_REPLY, exMsg.getPayload().getClass().getSimpleName())
       .debug();
   LOG.trace("Caught exception while servicing: " + exMsg.getPayload());
   final Throwable exception = exMsg.getException();
   if (exception instanceof MessagingException
       && exception.getCause() instanceof EucalyptusCloudException) {
     try {
       final EucalyptusCloudException cloudException =
           (EucalyptusCloudException) exception.getCause();
       final BaseMessage payload = parsePayload(exMsg.getPayload());
       final HttpResponseStatus status;
       final Role role;
       final String code;
       if (cloudException instanceof EucalyptusWebServiceException) {
         final EucalyptusWebServiceException webServiceException =
             (EucalyptusWebServiceException) cloudException;
         role = webServiceException.getRole();
         code = webServiceException.getCode();
       } else {
         role = Role.Receiver;
         code = defaultCode;
       }
       final QueryBindingInfo info =
           Ats.inClassHierarchy(cloudException.getClass()).get(QueryBindingInfo.class);
       status =
           info == null
               ? HttpResponseStatus.INTERNAL_SERVER_ERROR
               : new HttpResponseStatus(info.statusCode(), code);
       final BaseMessage errorResp =
           buildErrorResponse(payload.getCorrelationId(), role, code, cloudException.getMessage());
       Contexts.response(new BaseMessageSupplier(errorResp, status));
     } catch (final PayloadParseException e) {
       LOG.error("Failed to parse payload ", e.getCause());
     }
   } else {
     LOG.error("Unable to handle exception", exception);
     final BaseMessage errorResp = buildFatalResponse(exception);
     Contexts.response(
         new BaseMessageSupplier(errorResp, HttpResponseStatus.INTERNAL_SERVER_ERROR));
   }
 }
 public void handle(BaseMessage responseMessage) {
   EventRecord.here(
           EuareReplyQueue.class,
           EventType.MSG_REPLY,
           responseMessage.getCorrelationId(),
           responseMessage.getClass().getSimpleName())
       .debug();
   LOG.debug("HERE: " + responseMessage);
   String corrId = responseMessage.getCorrelationId();
   try {
     Context context = Contexts.lookup(corrId);
     Channel channel = context.getChannel();
     Channels.write(channel, responseMessage);
     Contexts.clear(context);
   } catch (NoSuchContextException e) {
     LOG.warn("Received a reply for absent client:  No channel to write response message.", e);
     LOG.debug(responseMessage);
   }
 }
Exemplo n.º 10
0
 static FilteredPipeline find(final HttpRequest request)
     throws DuplicatePipelineException, NoAcceptingPipelineException {
   final FilteredPipeline candidate = findAccepting(request);
   if (candidate == null) {
     if (Logs.isExtrrreeeme()) {
       if (request instanceof MappingHttpMessage) {
         ((MappingHttpMessage) request).logMessage();
         for (final FilteredPipeline p : pipelines) {
           LOG.debug("PIPELINE: " + p);
         }
         for (final FilteredPipeline p : internalPipelines) {
           LOG.debug("PIPELINE: " + p);
         }
       }
     }
     throw new NoAcceptingPipelineException();
   }
   if (Logs.isExtrrreeeme()) {
     EventRecord.here(Pipelines.class, EventType.PIPELINE_UNROLL, candidate.toString()).extreme();
   }
   return candidate;
 }
 private void clearState() {
   EventRecord.here(
           AssignAddressCallback.class,
           EventType.ADDRESS_ASSIGNING,
           Transition.assigning.toString(),
           "FAILED",
           this.address.toString())
       .debug();
   if (this.address.isPending()) {
     try {
       this.address.clearPending();
     } catch (Exception ex) {
     }
   }
   if (this.address.isSystemOwned()) {
     Addresses.release(this.address);
   } else if (this.address.isAssigned() && this.vm != null) {
     AddressingDispatcher.dispatch(
         AsyncRequests.newRequest(this.address.unassign().getCallback()), vm.getPartition());
   } else if (this.address.isAssigned() && this.vm == null) {
     this.address.unassign().clearPending();
   }
 }
 public void handle(ExceptionMessage exMsg) {
   EventRecord.here(
           EuareReplyQueue.class,
           EventType.MSG_REPLY,
           exMsg.getPayload().getClass().getSimpleName())
       .debug();
   LOG.trace("Caught exception while servicing: " + exMsg.getPayload());
   Throwable exception = exMsg.getException();
   if (exception instanceof MessagingException
       && exception.getCause() instanceof EucalyptusCloudException) {
     HttpResponseStatus status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
     String errorName = EuareException.INTERNAL_FAILURE;
     if (exception.getCause() instanceof EuareException) {
       EuareException euareException = (EuareException) exception.getCause();
       status = euareException.getStatus();
       errorName = euareException.getError();
     }
     ErrorResponseType errorResp = new ErrorResponseType();
     BaseMessage payload = null;
     try {
       payload = parsePayload(((MessagingException) exception).getUmoMessage().getPayload());
     } catch (Exception e) {
       LOG.error("Failed to parse payload ", e);
     }
     if (payload != null) {
       errorResp.setHttpStatus(status);
       errorResp.setCorrelationId(payload.getCorrelationId());
       errorResp.setRequestId(payload.getCorrelationId());
       ErrorType error = new ErrorType();
       error.setType("Sender");
       error.setCode(errorName);
       error.setMessage(exception.getCause().getMessage());
       errorResp.getErrorList().add(error);
       this.handle(errorResp);
     }
   }
 }
Exemplo n.º 13
0
 @Override
 public boolean apply(Allocation allocInfo) {
   if (EventRecord.isTraceEnabled(AdmissionControl.class)) {
     EventRecord.here(
             AdmissionControl.class, EventType.VM_RESERVED, LogUtil.dumpObject(allocInfo))
         .trace();
   }
   List<ResourceAllocator> finished = Lists.newArrayList();
   EntityTransaction db = Entities.get(NetworkGroup.class);
   try {
     for (ResourceAllocator allocator : allocators) {
       runAllocatorSafely(allocInfo, allocator);
       finished.add(allocator);
     }
     db.commit();
     return true;
   } catch (Exception ex) {
     Logs.exhaust().error(ex, ex);
     rollbackAllocations(allocInfo, finished, ex);
     db.rollback();
     throw Exceptions.toUndeclared(
         new NotEnoughResourcesException(Exceptions.getCauseMessage(ex), ex));
   }
 }
Exemplo n.º 14
0
  public DetachVolumeResponseType detach(DetachVolumeType request) throws EucalyptusCloudException {
    DetachVolumeResponseType reply = (DetachVolumeResponseType) request.getReply();
    Context ctx = Contexts.lookup();

    Volume vol;
    try {
      vol = Volumes.lookup(ctx.getUserFullName().asAccountFullName(), request.getVolumeId());
    } catch (Exception ex1) {
      throw new EucalyptusCloudException("Volume does not exist: " + request.getVolumeId());
    }
    if (!RestrictedTypes.filterPrivileged().apply(vol)) {
      throw new EucalyptusCloudException(
          "Not authorized to detach volume "
              + request.getVolumeId()
              + " by "
              + ctx.getUser().getName());
    }

    VmInstance vm = null;
    AttachedVolume volume = null;
    try {
      VmVolumeAttachment vmVolAttach = VmInstances.lookupVolumeAttachment(request.getVolumeId());
      volume = VmVolumeAttachment.asAttachedVolume(vmVolAttach.getVmInstance()).apply(vmVolAttach);
      vm = vmVolAttach.getVmInstance();
    } catch (NoSuchElementException ex) {
      /** no such attachment * */
    }
    if (volume == null) {
      throw new EucalyptusCloudException("Volume is not attached: " + request.getVolumeId());
    }
    if (!RestrictedTypes.filterPrivileged().apply(vm)) {
      throw new EucalyptusCloudException(
          "Not authorized to detach volume from instance "
              + request.getInstanceId()
              + " by "
              + ctx.getUser().getName());
    }
    if (!vm.getInstanceId().equals(request.getInstanceId())
        && request.getInstanceId() != null
        && !request.getInstanceId().equals("")) {
      throw new EucalyptusCloudException(
          "Volume is not attached to instance: " + request.getInstanceId());
    }
    if (request.getDevice() != null
        && !request.getDevice().equals("")
        && !volume.getDevice().equals(request.getDevice())) {
      throw new EucalyptusCloudException(
          "Volume is not attached to device: " + request.getDevice());
    }

    Cluster cluster = null;
    ServiceConfiguration ccConfig = null;
    try {
      ccConfig = Topology.lookup(ClusterController.class, vm.lookupPartition());
      cluster = Clusters.lookup(ccConfig);
    } catch (NoSuchElementException e) {
      LOG.debug(e, e);
      throw new EucalyptusCloudException(
          "Cluster does not exist in partition: " + vm.getPartition());
    }
    ServiceConfiguration scVm;
    try {
      scVm = Topology.lookup(Storage.class, vm.lookupPartition());
    } catch (Exception ex) {
      LOG.error(ex, ex);
      throw new EucalyptusCloudException(
          "Failed to lookup SC for partition: " + vm.getPartition(), ex);
    }
    request.setVolumeId(volume.getVolumeId());
    request.setRemoteDevice(volume.getRemoteDevice());
    request.setDevice(volume.getDevice().replaceAll("unknown,requested:", ""));
    request.setInstanceId(vm.getInstanceId());
    VolumeDetachCallback ncDetach = new VolumeDetachCallback(request);
    try {
      AsyncRequests.sendSync(scVm, new DetachStorageVolumeType(volume.getVolumeId()));
    } catch (Exception e) {
      LOG.debug(e);
      Logs.extreme().debug(e, e);
      // GRZE: attach is idempotent, failure here is ok.      throw new EucalyptusCloudException(
      // e.getMessage( ) );
    }
    AsyncRequests.newRequest(ncDetach).dispatch(cluster.getConfiguration());
    EventRecord.here(VolumeManager.class, EventClass.VOLUME, EventType.VOLUME_DETACH)
        .withDetails(vm.getOwner().toString(), volume.getVolumeId(), "instance", vm.getInstanceId())
        .withDetails("cluster", ccConfig.getFullName().toString())
        .info();
    volume.setStatus("detaching");
    reply.setDetachedVolume(volume);
    return reply;
  }
Exemplo n.º 15
0
  public AttachVolumeResponseType AttachVolume(AttachVolumeType request)
      throws EucalyptusCloudException {
    AttachVolumeResponseType reply = (AttachVolumeResponseType) request.getReply();
    final String deviceName = request.getDevice();
    final String volumeId = request.getVolumeId();
    final Context ctx = Contexts.lookup();

    if (request.getDevice() == null
        || request.getDevice().endsWith("sda")
        || request.getDevice().endsWith("sdb")) {
      throw new EucalyptusCloudException("Invalid device name specified: " + request.getDevice());
    }
    VmInstance vm = null;
    try {
      vm = RestrictedTypes.doPrivileged(request.getInstanceId(), VmInstance.class);
    } catch (NoSuchElementException ex) {
      LOG.debug(ex, ex);
      throw new EucalyptusCloudException("Instance does not exist: " + request.getInstanceId(), ex);
    } catch (Exception ex) {
      LOG.debug(ex, ex);
      throw new EucalyptusCloudException(ex.getMessage(), ex);
    }
    AccountFullName ownerFullName = ctx.getUserFullName().asAccountFullName();
    Volume volume = Volumes.lookup(ownerFullName, volumeId);
    if (!RestrictedTypes.filterPrivileged().apply(volume)) {
      throw new EucalyptusCloudException(
          "Not authorized to attach volume "
              + request.getVolumeId()
              + " by "
              + ctx.getUser().getName());
    }
    try {
      vm.lookupVolumeAttachmentByDevice(deviceName);
      throw new EucalyptusCloudException(
          "Already have a device attached to: " + request.getDevice());
    } catch (NoSuchElementException ex1) {
      /** no attachment * */
    }
    try {
      VmInstances.lookupVolumeAttachment(volumeId);
      throw new EucalyptusCloudException("Volume already attached: " + request.getVolumeId());
    } catch (NoSuchElementException ex1) {
      /** no attachment * */
    }

    Partition volPartition = Partitions.lookupByName(volume.getPartition());
    ServiceConfiguration sc = Topology.lookup(Storage.class, volPartition);
    ServiceConfiguration scVm = Topology.lookup(Storage.class, vm.lookupPartition());
    if (!sc.equals(scVm)) {
      throw new EucalyptusCloudException(
          "Can only attach volumes in the same zone: " + request.getVolumeId());
    }
    ServiceConfiguration ccConfig = Topology.lookup(ClusterController.class, vm.lookupPartition());
    AttachStorageVolumeResponseType scAttachResponse;
    try {
      AttachStorageVolumeType req =
          new AttachStorageVolumeType(Nodes.lookupIqn(vm), volume.getDisplayName());
      scAttachResponse = AsyncRequests.sendSync(sc, req);
    } catch (Exception e) {
      LOG.debug(e, e);
      throw new EucalyptusCloudException(e.getMessage(), e);
    }
    request.setRemoteDevice(scAttachResponse.getRemoteDeviceString());

    AttachedVolume attachVol =
        new AttachedVolume(
            volume.getDisplayName(),
            vm.getInstanceId(),
            request.getDevice(),
            request.getRemoteDevice());
    vm.addTransientVolume(deviceName, scAttachResponse.getRemoteDeviceString(), volume);
    AsyncRequests.newRequest(new VolumeAttachCallback(request)).dispatch(ccConfig);

    EventRecord.here(VolumeManager.class, EventClass.VOLUME, EventType.VOLUME_ATTACH)
        .withDetails(
            volume.getOwner().toString(), volume.getDisplayName(), "instance", vm.getInstanceId())
        .withDetails("partition", vm.getPartition().toString())
        .info();
    reply.setAttachedVolume(attachVol);
    return reply;
  }