Пример #1
0
  private void handle(final APIAttachDataVolumeToVmMsg msg) {
    self.setVmInstanceUuid(msg.getVmInstanceUuid());
    self = dbf.updateAndRefresh(self);

    AttachDataVolumeToVmMsg amsg = new AttachDataVolumeToVmMsg();
    amsg.setVolume(getSelfInventory());
    amsg.setVmInstanceUuid(msg.getVmInstanceUuid());
    bus.makeTargetServiceIdByResourceUuid(
        amsg, VmInstanceConstant.SERVICE_ID, amsg.getVmInstanceUuid());
    bus.send(
        amsg,
        new CloudBusCallBack(msg) {
          @Override
          public void run(MessageReply reply) {
            final APIAttachDataVolumeToVmEvent evt = new APIAttachDataVolumeToVmEvent(msg.getId());
            self = dbf.reload(self);
            if (reply.isSuccess()) {
              AttachDataVolumeToVmReply ar = reply.castReply();
              self.setVmInstanceUuid(msg.getVmInstanceUuid());
              self.setFormat(
                  VolumeFormat.getVolumeFormatByMasterHypervisorType(ar.getHypervisorType())
                      .toString());
              self = dbf.updateAndRefresh(self);

              evt.setInventory(getSelfInventory());
            } else {
              self.setVmInstanceUuid(null);
              dbf.update(self);
              evt.setErrorCode(reply.getError());
            }

            bus.publish(evt);
          }
        });
  }
Пример #2
0
  private void handle(final CreateDataVolumeTemplateFromDataVolumeMsg msg) {
    final CreateTemplateFromVolumeOnPrimaryStorageMsg cmsg =
        new CreateTemplateFromVolumeOnPrimaryStorageMsg();
    cmsg.setBackupStorageUuid(msg.getBackupStorageUuid());
    cmsg.setImageInventory(
        ImageInventory.valueOf(dbf.findByUuid(msg.getImageUuid(), ImageVO.class)));
    cmsg.setVolumeInventory(getSelfInventory());
    bus.makeTargetServiceIdByResourceUuid(
        cmsg, PrimaryStorageConstant.SERVICE_ID, self.getPrimaryStorageUuid());
    bus.send(
        cmsg,
        new CloudBusCallBack(msg) {
          @Override
          public void run(MessageReply r) {
            CreateDataVolumeTemplateFromDataVolumeReply reply =
                new CreateDataVolumeTemplateFromDataVolumeReply();
            if (!r.isSuccess()) {
              reply.setError(r.getError());
            } else {
              CreateTemplateFromVolumeOnPrimaryStorageReply creply = r.castReply();
              String backupStorageInstallPath = creply.getTemplateBackupStorageInstallPath();
              reply.setFormat(creply.getFormat());
              reply.setInstallPath(backupStorageInstallPath);
              reply.setMd5sum(null);
              reply.setBackupStorageUuid(msg.getBackupStorageUuid());
            }

            bus.reply(msg, reply);
          }
        });
  }
Пример #3
0
  private void syncVolumeVolumeSize(final ReturnValueCompletion<VolumeSize> completion) {
    SyncVolumeSizeOnPrimaryStorageMsg smsg = new SyncVolumeSizeOnPrimaryStorageMsg();
    smsg.setPrimaryStorageUuid(self.getPrimaryStorageUuid());
    smsg.setVolumeUuid(self.getUuid());
    smsg.setInstallPath(self.getInstallPath());
    bus.makeTargetServiceIdByResourceUuid(
        smsg, PrimaryStorageConstant.SERVICE_ID, self.getPrimaryStorageUuid());
    bus.send(
        smsg,
        new CloudBusCallBack(completion) {
          @Override
          public void run(MessageReply reply) {
            if (!reply.isSuccess()) {
              completion.fail(reply.getError());
              return;
            }

            SyncVolumeSizeOnPrimaryStorageReply r = reply.castReply();
            self.setActualSize(r.getActualSize());
            self.setSize(r.getSize());
            self = dbf.updateAndRefresh(self);

            VolumeSize size = new VolumeSize();
            size.actualSize = r.getActualSize();
            size.size = r.getSize();
            completion.success(size);
          }
        });
  }
Пример #4
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    long requiredSize = SizeUnit.GIGABYTE.toByte(10);
    SimulatorPrimaryStorageDetails sp = new SimulatorPrimaryStorageDetails();
    sp.setTotalCapacity(SizeUnit.TERABYTE.toByte(10));
    sp.setAvailableCapacity(sp.getTotalCapacity());
    sp.setUrl("nfs://simulator/primary/");
    PrimaryStorageInventory pinv = api.createSimulatoPrimaryStorage(1, sp).get(0);
    ZoneInventory zone = api.createZones(1).get(0);
    ClusterInventory cluster = api.createClusters(1, zone.getUuid()).get(0);
    HostInventory host = api.createHost(1, cluster.getUuid()).get(0);
    api.attachPrimaryStorage(cluster.getUuid(), pinv.getUuid());

    AllocatePrimaryStorageMsg msg = new AllocatePrimaryStorageMsg();
    msg.setRequiredHostUuid(host.getUuid());
    msg.setSize(requiredSize);
    msg.setServiceId(bus.makeLocalServiceId(PrimaryStorageConstant.SERVICE_ID));
    MessageReply reply = bus.call(msg);
    Assert.assertEquals(AllocatePrimaryStorageReply.class, reply.getClass());
    AllocatePrimaryStorageReply ar = (AllocatePrimaryStorageReply) reply;
    Assert.assertEquals(pinv.getUuid(), ar.getPrimaryStorageInventory().getUuid());

    ReturnPrimaryStorageCapacityMsg rmsg = new ReturnPrimaryStorageCapacityMsg();
    rmsg.setDiskSize(requiredSize);
    rmsg.setPrimaryStorageUuid(pinv.getUuid());
    rmsg.setServiceId(bus.makeLocalServiceId(PrimaryStorageConstant.SERVICE_ID));
    bus.send(rmsg);
    Thread.sleep(2000);
    PrimaryStorageVO pvo = dbf.findByUuid(pinv.getUuid(), PrimaryStorageVO.class);
    Assert.assertEquals(
        pvo.getCapacity().getTotalCapacity(), pvo.getCapacity().getAvailableCapacity());
  }
Пример #5
0
  private void handle(final ExpungeImageMsg msg) {
    final ExpungeImageReply reply = new ExpungeImageReply();
    final ImageBackupStorageRefVO ref =
        CollectionUtils.find(
            self.getBackupStorageRefs(),
            new Function<ImageBackupStorageRefVO, ImageBackupStorageRefVO>() {
              @Override
              public ImageBackupStorageRefVO call(ImageBackupStorageRefVO arg) {
                return arg.getBackupStorageUuid().equals(msg.getBackupStorageUuid()) ? arg : null;
              }
            });

    if (ref == null) {
      logger.debug(
          String.format(
              "cannot find reference for the image[uuid:%s] on the backup storage[uuid:%s], assume it's been deleted",
              self.getUuid(), msg.getBackupStorageUuid()));
      bus.reply(msg, reply);
      return;
    }

    DeleteBitsOnBackupStorageMsg dmsg = new DeleteBitsOnBackupStorageMsg();
    dmsg.setBackupStorageUuid(ref.getBackupStorageUuid());
    dmsg.setInstallPath(ref.getInstallPath());
    bus.makeTargetServiceIdByResourceUuid(
        dmsg, BackupStorageConstant.SERVICE_ID, dmsg.getBackupStorageUuid());
    bus.send(
        dmsg,
        new CloudBusCallBack(msg) {
          @Override
          public void run(MessageReply r) {
            if (!r.isSuccess()) {
              // TODO
              logger.warn(
                  String.format(
                      "failed to delete image[uuid:%s, name:%s] from backup storage[uuid:%s] because %s, need to garbage collect it",
                      self.getUuid(), self.getName(), r.getError(), ref.getBackupStorageUuid()));
              reply.setError(r.getError());
            } else {
              returnBackupStorageCapacity(ref.getBackupStorageUuid(), self.getSize());
              dbf.remove(ref);
              logger.debug(
                  String.format(
                      "successfully expunged the image[uuid: %s, name: %s] on the backup storage[uuid: %s]",
                      self.getUuid(), self.getName(), ref.getBackupStorageUuid()));
              self = dbf.findByUuid(self.getUuid(), ImageVO.class);
              if (self.getBackupStorageRefs().isEmpty()) {
                logger.debug(
                    String.format(
                        "the image[uuid:%s, name:%s] has been expunged on all backup storage, remove it from database",
                        self.getUuid(), self.getName()));
                dbf.remove(self);
              }
            }

            bus.reply(msg, reply);
          }
        });
  }
  private void handle(APIDetachNetworkServiceProviderFromL2NetworkMsg msg) {
    NetworkServiceProviderVO vo =
        dbf.findByUuid(msg.getNetworkServiceProviderUuid(), NetworkServiceProviderVO.class);
    NetworkServiceProviderFactory factory = getProviderFactory(vo.getType());
    NetworkServiceProvider provider = factory.getNetworkServiceProvider(vo);
    L2NetworkVO l2vo = dbf.findByUuid(msg.getL2NetworkUuid(), L2NetworkVO.class);

    APIDetachNetworkServiceProviderFromL2NetworkEvent evt =
        new APIDetachNetworkServiceProviderFromL2NetworkEvent(msg.getId());
    try {
      provider.detachFromL2Network(L2NetworkInventory.valueOf(l2vo), msg);
    } catch (NetworkException e) {
      String err =
          String.format(
              "unable to detach network service provider[uuid:%s, name:%s, type:%s] to l2network[uuid:%s, name:%s, type:%s], %s",
              vo.getUuid(),
              vo.getName(),
              vo.getType(),
              l2vo.getUuid(),
              l2vo.getName(),
              l2vo.getType(),
              e.getMessage());
      logger.warn(err, e);
      evt.setErrorCode(
          errf.instantiateErrorCode(
              NetworkServiceErrors.DETACH_NETWORK_SERVICE_PROVIDER_ERROR, err));
      bus.publish(evt);
      return;
    }

    SimpleQuery<NetworkServiceProviderL2NetworkRefVO> query =
        dbf.createQuery(NetworkServiceProviderL2NetworkRefVO.class);
    query.select(NetworkServiceProviderL2NetworkRefVO_.id);
    query.add(NetworkServiceProviderL2NetworkRefVO_.l2NetworkUuid, Op.EQ, l2vo.getUuid());
    query.add(
        NetworkServiceProviderL2NetworkRefVO_.networkServiceProviderUuid, Op.EQ, vo.getUuid());
    Long id = query.findValue();
    if (id != null) {
      dbf.removeByPrimaryKey(id, NetworkServiceProviderL2NetworkRefVO.class);
    }

    vo = dbf.findByUuid(vo.getUuid(), NetworkServiceProviderVO.class);
    evt.setInventory(NetworkServiceProviderInventory.valueOf(vo));
    String info =
        String.format(
            "successfully detach network service provider[uuid:%s, name:%s, type:%s] to l2network[uuid:%s, name:%s, type:%s]",
            vo.getUuid(),
            vo.getName(),
            vo.getType(),
            l2vo.getUuid(),
            l2vo.getName(),
            l2vo.getType());
    logger.debug(info);
    bus.publish(evt);
  }
Пример #7
0
 @Override
 public void handleMessage(Message msg) {
   try {
     if (msg instanceof APIMessage) {
       handleApiMessage((APIMessage) msg);
     } else {
       handleLocalMessage(msg);
     }
   } catch (Exception e) {
     bus.logExceptionWithMessageDump(msg, e);
     bus.replyErrorByMessageType(msg, e);
   }
 }
Пример #8
0
 @Override
 public void afterHostConnected(HostInventory host) {
   SimpleQuery<LocalStorageHostRefVO> q = dbf.createQuery(LocalStorageHostRefVO.class);
   q.add(LocalStorageHostRefVO_.hostUuid, Op.EQ, host.getUuid());
   LocalStorageHostRefVO ref = q.find();
   if (ref != null) {
     RecalculatePrimaryStorageCapacityMsg msg = new RecalculatePrimaryStorageCapacityMsg();
     msg.setPrimaryStorageUuid(ref.getPrimaryStorageUuid());
     bus.makeTargetServiceIdByResourceUuid(
         msg, PrimaryStorageConstant.SERVICE_ID, ref.getPrimaryStorageUuid());
     bus.send(msg);
   }
 }
  @Override
  public void run(final FlowTrigger trigger, final Map data) {
    final VmInstanceSpec spec =
        (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString());
    VolumeInventory volume = spec.getDestDataVolumes().get(0);

    SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class);
    q.select(LocalStorageResourceRefVO_.hostUuid, LocalStorageResourceRefVO_.primaryStorageUuid);
    q.add(
        LocalStorageResourceRefVO_.resourceUuid, Op.EQ, spec.getVmInventory().getRootVolumeUuid());
    Tuple t = q.findTuple();
    final String hostUuid = t.get(0, String.class);
    String priUuid = t.get(1, String.class);

    AllocatePrimaryStorageMsg msg = new AllocatePrimaryStorageMsg();
    if (isThereOtherStorageForTheHost(hostUuid, priUuid)) {
      // use network-shared primary storage
      msg.addExcludeAllocatorStrategy(LocalStorageConstants.LOCAL_STORAGE_ALLOCATOR_STRATEGY);
      msg.addExcludePrimaryStoratgeUuid(priUuid);
    } else {
      msg.setAllocationStrategy(LocalStorageConstants.LOCAL_STORAGE_ALLOCATOR_STRATEGY);
      msg.setRequiredPrimaryStorageUuid(
          spec.getVmInventory().getRootVolume().getPrimaryStorageUuid());
    }

    msg.setRequiredHostUuid(hostUuid);
    msg.setVmInstanceUuid(spec.getVmInventory().getUuid());
    msg.setSize(volume.getSize());
    msg.setPurpose(PrimaryStorageAllocationPurpose.CreateVolume.toString());
    bus.makeLocalServiceId(msg, PrimaryStorageConstant.SERVICE_ID);
    bus.send(
        msg,
        new CloudBusCallBack(trigger) {
          @Override
          public void run(MessageReply reply) {
            if (!reply.isSuccess()) {
              trigger.fail(reply.getError());
              return;
            }

            spec.setDestHost(HostInventory.valueOf(dbf.findByUuid(hostUuid, HostVO.class)));

            AllocatePrimaryStorageReply ar = (AllocatePrimaryStorageReply) reply;
            data.put(
                VmInstanceConstant.Params.DestPrimaryStorageInventoryForAttachingVolume.toString(),
                ar.getPrimaryStorageInventory());
            data.put(LocalStorageAllocateCapacityForAttachingVolumeFlow.class, ar.getSize());
            trigger.next();
          }
        });
  }
Пример #10
0
  private void handle(APIAttachNetworkServiceProviderToL2NetworkMsg msg) {
    NetworkServiceProviderVO vo =
        dbf.findByUuid(msg.getNetworkServiceProviderUuid(), NetworkServiceProviderVO.class);
    NetworkServiceProviderFactory factory = getProviderFactory(vo.getType());
    NetworkServiceProvider provider = factory.getNetworkServiceProvider(vo);
    L2NetworkVO l2vo = dbf.findByUuid(msg.getL2NetworkUuid(), L2NetworkVO.class);

    APIAttachNetworkServiceProviderToL2NetworkEvent evt =
        new APIAttachNetworkServiceProviderToL2NetworkEvent(msg.getId());
    try {
      provider.attachToL2Network(L2NetworkInventory.valueOf(l2vo), msg);
    } catch (NetworkException e) {
      String err =
          String.format(
              "unable to attach network service provider[uuid:%s, name:%s, type:%s] to l2network[uuid:%s, name:%s, type:%s], %s",
              vo.getUuid(),
              vo.getName(),
              vo.getType(),
              l2vo.getUuid(),
              l2vo.getName(),
              l2vo.getType(),
              e.getMessage());
      logger.warn(err, e);
      evt.setErrorCode(
          errf.instantiateErrorCode(
              NetworkServiceErrors.ATTACH_NETWORK_SERVICE_PROVIDER_ERROR, err));
      bus.publish(evt);
      return;
    }

    NetworkServiceProviderL2NetworkRefVO ref = new NetworkServiceProviderL2NetworkRefVO();
    ref.setL2NetworkUuid(l2vo.getUuid());
    ref.setNetworkServiceProviderUuid(vo.getUuid());
    dbf.persist(ref);

    vo = dbf.findByUuid(vo.getUuid(), NetworkServiceProviderVO.class);
    evt.setInventory(NetworkServiceProviderInventory.valueOf(vo));
    String info =
        String.format(
            "successfully attach network service provider[uuid:%s, name:%s, type:%s] to l2network[uuid:%s, name:%s, type:%s]",
            vo.getUuid(),
            vo.getName(),
            vo.getType(),
            l2vo.getUuid(),
            l2vo.getName(),
            l2vo.getType());
    logger.debug(info);
    bus.publish(evt);
  }
Пример #11
0
 protected void handleLocalMessage(Message msg) throws URISyntaxException {
   if (msg instanceof DownloadImageMsg) {
     handleBase((DownloadImageMsg) msg);
   } else if (msg instanceof ScanBackupStorageMsg) {
     handle((ScanBackupStorageMsg) msg);
   } else if (msg instanceof BackupStorageDeletionMsg) {
     handle((BackupStorageDeletionMsg) msg);
   } else if (msg instanceof ChangeBackupStorageStatusMsg) {
     handle((ChangeBackupStorageStatusMsg) msg);
   } else if (msg instanceof ConnectBackupStorageMsg) {
     handle((ConnectBackupStorageMsg) msg);
   } else if (msg instanceof ReturnBackupStorageMsg) {
     handle((ReturnBackupStorageMsg) msg);
   } else if (msg instanceof DownloadVolumeMsg) {
     handleBase((DownloadVolumeMsg) msg);
   } else if (msg instanceof DeleteBitsOnBackupStorageMsg) {
     handleBase((DeleteBitsOnBackupStorageMsg) msg);
   } else if (msg instanceof PingBackupStorageMsg) {
     handle((PingBackupStorageMsg) msg);
   } else if (msg instanceof BackupStorageAskInstallPathMsg) {
     handle((BackupStorageAskInstallPathMsg) msg);
   } else if (msg instanceof SyncImageSizeOnBackupStorageMsg) {
     handle((SyncImageSizeOnBackupStorageMsg) msg);
   } else if (msg instanceof GetImageSizeOnBackupStorageMsg) {
     handle((GetImageSizeOnBackupStorageMsg) msg);
   } else {
     bus.dealWithUnknownMessage(msg);
   }
 }
  @Override
  public void contextInitialized(ServletContextEvent event) {
    try {
      if (!isInit) {
        Platform.createComponentLoaderFromWebApplicationContext(
            WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()));
        node = Platform.getComponentLoader().getComponent(ManagementNodeManager.class);
        bus = Platform.getComponentLoader().getComponent(CloudBus.class);
        node.startNode();
        isInit = true;
      }
    } catch (Throwable t) {
      logger.warn("failed to start management server", t);
      // have to call bus.stop() because its init has been called by spring
      if (bus != null) {
        bus.stop();
      }

      Throwable root = ExceptionDSL.getRootThrowable(t);
      new BootErrorLog().write(root.getMessage());
      if (CoreGlobalProperty.EXIT_JVM_ON_BOOT_FAILURE) {
        System.exit(1);
      } else {
        throw new CloudRuntimeException(t);
      }
    }
  }
Пример #13
0
 private void handle(APISearchZoneMsg msg) {
   SearchQuery<ZoneInventory> query = SearchQuery.create(msg, ZoneInventory.class);
   String res = query.listAsString();
   APISearchZoneReply reply = new APISearchZoneReply();
   reply.setContent(res);
   bus.reply(msg, reply);
 }
Пример #14
0
 private void handle(APIGetZoneMsg msg) {
   GetQuery query = new GetQuery();
   String inv = query.getAsString(msg.getUuid(), ZoneInventory.class);
   APIGetZoneReply reply = new APIGetZoneReply();
   reply.setInventory(inv);
   bus.reply(msg, reply);
 }
Пример #15
0
 protected void handleLocalMessage(Message msg) {
   if (msg instanceof PrimaryStorageReportPhysicalCapacityMsg) {
     handle((PrimaryStorageReportPhysicalCapacityMsg) msg);
   } else if (msg instanceof InstantiateVolumeMsg) {
     handle((InstantiateVolumeMsg) msg);
   } else if (msg instanceof DeleteVolumeOnPrimaryStorageMsg) {
     handle((DeleteVolumeOnPrimaryStorageMsg) msg);
   } else if (msg instanceof CreateTemplateFromVolumeOnPrimaryStorageMsg) {
     handleBase((CreateTemplateFromVolumeOnPrimaryStorageMsg) msg);
   } else if (msg instanceof PrimaryStorageDeletionMsg) {
     handle((PrimaryStorageDeletionMsg) msg);
   } else if (msg instanceof DetachPrimaryStorageFromClusterMsg) {
     handle((DetachPrimaryStorageFromClusterMsg) msg);
   } else if (msg instanceof DownloadDataVolumeToPrimaryStorageMsg) {
     handleBase((DownloadDataVolumeToPrimaryStorageMsg) msg);
   } else if (msg instanceof DeleteBitsOnPrimaryStorageMsg) {
     handle((DeleteBitsOnPrimaryStorageMsg) msg);
   } else if (msg instanceof ConnectPrimaryStorageMsg) {
     handle((ConnectPrimaryStorageMsg) msg);
   } else if (msg instanceof DownloadIsoToPrimaryStorageMsg) {
     handleBase((DownloadIsoToPrimaryStorageMsg) msg);
   } else if (msg instanceof DeleteIsoFromPrimaryStorageMsg) {
     handle((DeleteIsoFromPrimaryStorageMsg) msg);
   } else if (msg instanceof AskVolumeSnapshotCapabilityMsg) {
     handle((AskVolumeSnapshotCapabilityMsg) msg);
   } else if (msg instanceof SyncVolumeSizeOnPrimaryStorageMsg) {
     handle((SyncVolumeSizeOnPrimaryStorageMsg) msg);
   } else {
     bus.dealWithUnknownMessage(msg);
   }
 }
Пример #16
0
  private void handle(APICreateZoneMsg msg) {
    String zoneType = msg.getType();
    if (zoneType == null) {
      zoneType = BaseZoneFactory.type.toString();
    }
    ZoneFactory factory = this.getZoneFactory(ZoneType.valueOf(zoneType));
    APICreateZoneEvent evt = new APICreateZoneEvent(msg.getId());
    ZoneVO vo = new ZoneVO();
    if (msg.getResourceUuid() != null) {
      vo.setUuid(msg.getResourceUuid());
    } else {
      vo.setUuid(Platform.getUuid());
    }
    vo.setName(msg.getName());
    vo.setDescription(msg.getDescription());
    vo = factory.createZone(vo, msg);

    tagMgr.createTagsFromAPICreateMessage(msg, vo.getUuid(), ZoneVO.class.getSimpleName());

    evt.setInventory(ZoneInventory.valueOf(vo));
    logger.debug("Created zone: " + vo.getName() + " uuid:" + vo.getUuid());
    if (logf.isEnabled()) {
      logf.info(vo.getUuid(), String.format("Create zone successfully"));
    }
    bus.publish(evt);
  }
Пример #17
0
 private void handle(APIListZonesMsg msg) {
   APIListZonesReply reply = new APIListZonesReply();
   List<ZoneVO> vos = dl.listByApiMessage(msg, ZoneVO.class);
   List<ZoneInventory> invs = ZoneInventory.valueOf(vos);
   reply.setInventories(invs);
   bus.reply(msg, reply);
 }
Пример #18
0
 private void handle(APIListNetworkServiceProviderMsg msg) {
   List<NetworkServiceProviderVO> vos = dl.listByApiMessage(msg, NetworkServiceProviderVO.class);
   List<NetworkServiceProviderInventory> invs = NetworkServiceProviderInventory.valueOf(vos);
   APIListNetworkServiceProviderReply reply = new APIListNetworkServiceProviderReply();
   reply.setInventories(invs);
   bus.reply(msg, reply);
 }
Пример #19
0
 private void handleLocalMessage(Message msg) {
   if (msg instanceof DiskOfferingDeletionMsg) {
     handle((DiskOfferingDeletionMsg) msg);
   } else {
     bus.dealWithUnknownMessage(msg);
   }
 }
Пример #20
0
 private void handle(APIGetNetworkServiceProviderMsg msg) {
   GetQuery q = new GetQuery();
   String res = q.getAsString(msg, NetworkServiceProviderInventory.class);
   APIGetNetworkServiceProviderReply reply = new APIGetNetworkServiceProviderReply();
   reply.setInventory(res);
   bus.reply(msg, reply);
 }
Пример #21
0
 private void handle(APIQueryNetworkServiceProviderMsg msg) {
   List<NetworkServiceProviderInventory> invs =
       qf.query(msg, NetworkServiceProviderInventory.class);
   APIQueryNetworkServiceProviderReply reply = new APIQueryNetworkServiceProviderReply();
   reply.setInventories(invs);
   bus.reply(msg, reply);
 }
Пример #22
0
 private void handleLocalMessage(Message msg) {
   if (msg instanceof ZoneMessage) {
     passThrough((ZoneMessage) msg);
   } else {
     bus.dealWithUnknownMessage(msg);
   }
 }
Пример #23
0
    public static ComponentLoader createComponentLoaderFromWebApplicationContext(WebApplicationContext webAppCtx) {
        assert loader == null;
        try {
            if (webAppCtx != null) {
                loader = new ComponentLoaderImpl(webAppCtx);
            } else {
                loader = new ComponentLoaderImpl();
            }
        } catch (Exception e) {
            String err = "unable to create ComponentLoader";
            logger.warn(e.getMessage(), e);
            throw new CloudRuntimeException(err);
        }

        loader.getPluginRegistry();
        GlobalConfigFacade gcf = loader.getComponent(GlobalConfigFacade.class);
        if (gcf != null) {
            ((Component)gcf).start();
        }
        bus = loader.getComponentNoExceptionWhenNotExisting(CloudBus.class);
        if (bus != null)  {
            bus.start();
        }

        return loader;
    }
Пример #24
0
 private void handleApiMessage(APIMessage msg) {
   if (msg instanceof APIChangeVolumeStateMsg) {
     handle((APIChangeVolumeStateMsg) msg);
   } else if (msg instanceof APICreateVolumeSnapshotMsg) {
     handle((APICreateVolumeSnapshotMsg) msg);
   } else if (msg instanceof APIDeleteDataVolumeMsg) {
     handle((APIDeleteDataVolumeMsg) msg);
   } else if (msg instanceof APIDetachDataVolumeFromVmMsg) {
     handle((APIDetachDataVolumeFromVmMsg) msg);
   } else if (msg instanceof APIAttachDataVolumeToVmMsg) {
     handle((APIAttachDataVolumeToVmMsg) msg);
   } else if (msg instanceof APIGetDataVolumeAttachableVmMsg) {
     handle((APIGetDataVolumeAttachableVmMsg) msg);
   } else if (msg instanceof APIUpdateVolumeMsg) {
     handle((APIUpdateVolumeMsg) msg);
   } else if (msg instanceof APIRecoverDataVolumeMsg) {
     handle((APIRecoverDataVolumeMsg) msg);
   } else if (msg instanceof APIExpungeDataVolumeMsg) {
     handle((APIExpungeDataVolumeMsg) msg);
   } else if (msg instanceof APISyncVolumeSizeMsg) {
     handle((APISyncVolumeSizeMsg) msg);
   } else {
     bus.dealWithUnknownMessage(msg);
   }
 }
Пример #25
0
 private void handle(APISearchNetworkServiceProviderMsg msg) {
   SearchQuery<NetworkServiceProviderInventory> q =
       SearchQuery.create(msg, NetworkServiceProviderInventory.class);
   APISearchNetworkServiceProviderReply reply = new APISearchNetworkServiceProviderReply();
   String res = q.listAsString();
   reply.setContent(res);
   bus.reply(msg, reply);
 }
Пример #26
0
 private void handleLocalMessage(Message msg) {
   if (msg instanceof ImageDeletionMsg) {
     handle((ImageDeletionMsg) msg);
   } else if (msg instanceof ExpungeImageMsg) {
     handle((ExpungeImageMsg) msg);
   } else {
     bus.dealWithUnknownMessage(msg);
   }
 }
Пример #27
0
  private void handle(PrimaryStorageDeletionMsg msg) {
    PrimaryStorageInventory inv = PrimaryStorageInventory.valueOf(self);
    extpEmitter.beforeDelete(inv);
    deleteHook();
    extpEmitter.afterDelete(inv);

    PrimaryStorageDeletionReply reply = new PrimaryStorageDeletionReply();
    bus.reply(msg, reply);
  }
  @Override
  public void rollback(FlowRollback trigger, Map data) {
    Long size = (Long) data.get(LocalStorageAllocateCapacityForAttachingVolumeFlow.class);
    if (size != null) {
      PrimaryStorageInventory pri =
          (PrimaryStorageInventory)
              data.get(
                  VmInstanceConstant.Params.DestPrimaryStorageInventoryForAttachingVolume
                      .toString());
      ReturnPrimaryStorageCapacityMsg rmsg = new ReturnPrimaryStorageCapacityMsg();
      rmsg.setPrimaryStorageUuid(pri.getUuid());
      rmsg.setDiskSize(size);
      bus.makeTargetServiceIdByResourceUuid(rmsg, PrimaryStorageConstant.SERVICE_ID, pri.getUuid());
      bus.send(rmsg);
    }

    trigger.rollback();
  }
Пример #29
0
  private void handle(BackupStorageDeletionMsg msg) {
    BackupStorageInventory inv = BackupStorageInventory.valueOf(self);
    extpEmitter.beforeDelete(inv);
    deleteHook();
    extpEmitter.afterDelete(inv);

    BackupStorageDeletionReply reply = new BackupStorageDeletionReply();
    tracker.untrackHook(self.getUuid());
    bus.reply(msg, reply);
  }
Пример #30
0
  private void handle(APIUpdateBackupStorageMsg msg) {
    BackupStorageVO vo = updateBackupStorage(msg);
    if (vo != null) {
      self = dbf.updateAndRefresh(vo);
    }

    APIUpdateBackupStorageEvent evt = new APIUpdateBackupStorageEvent(msg.getId());
    evt.setInventory(getSelfInventory());
    bus.publish(evt);
  }