public void removeVmOnSimulatorHost(String hostUuid, String vmUuid) { RemoveVmOnSimulatorMsg msg = new RemoveVmOnSimulatorMsg(); msg.setHostUuid(hostUuid); msg.setVmUuid(vmUuid); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, hostUuid); bus.call(msg); } }
public void setSimulatorHostConnectionState(String uuid, boolean isDisconnected) { SimulatorHostConnectionControlMsg msg = new SimulatorHostConnectionControlMsg(); msg.setHostUuid(uuid); msg.setDisconnected(isDisconnected); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, uuid); bus.call(msg); }
@Override public RestAPIResponse call(APIMessage msg) { RestAPIResponse rsp = new RestAPIResponse(); rsp.setCreatedDate(new Date()); msg.setServiceId(ApiMediatorConstant.SERVICE_ID); MessageReply reply = bus.call(msg); rsp.setFinishedDate(new Date()); rsp.setState(RestAPIState.Done.toString()); rsp.setResult(RESTApiDecoder.dump(reply)); return rsp; }
public void setVmStateOnSimulatorHost(String hostUuid, String vmUuid, VmInstanceState vmState) { ChangeVmStateOnSimulatorHostMsg msg = new ChangeVmStateOnSimulatorHostMsg(); msg.setHostUuid(hostUuid); msg.setVmUuid(vmUuid); msg.setVmState(vmState.toString()); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, hostUuid); bus.call(msg); }
private void sendMessage(APIMessage msg, Api api, HttpServletResponse rsp) throws IOException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { if (msg instanceof APISyncCallMessage) { MessageReply reply = bus.call(msg); sendReplyResponse(reply, api, rsp); } else { RequestData d = new RequestData(); d.apiMessage = msg; d.requestInfo = requestInfo.get(); List<String> webHook = requestInfo.get().headers.get(RestConstants.HEADER_WEBHOOK); if (webHook != null && !webHook.isEmpty()) { d.webHook = webHook.get(0); } asyncStore.save(d); UriComponentsBuilder ub = UriComponentsBuilder.fromHttpUrl(restf.getBaseUrl()); ub.path(RestConstants.API_VERSION); ub.path(RestConstants.ASYNC_JOB_PATH); ub.path("/" + msg.getId()); ApiResponse response = new ApiResponse(); response.setLocation(ub.build().toUriString()); bus.send(msg); sendResponse(HttpStatus.ACCEPTED.value(), response, rsp); } }
gmsg.setUrl(url.split("://")[1]); bus.makeTargetServiceIdByResourceUuid(gmsg, BackupStorageConstant.SERVICE_ID, bsUuid); GetLocalFileSizeOnBackupStorageReply reply = (GetLocalFileSizeOnBackupStorageReply) bus.call(gmsg); if (!reply.isSuccess()) { logger.warn(String.format("cannot get image. The image url : %s. description: %s.name: %s",
private UsedIpInventory acquireIp(String l3NetworkUuid, String mac, String stratgey) { AllocateIpMsg msg = new AllocateIpMsg(); msg.setL3NetworkUuid(l3NetworkUuid); l3nm.updateIpAllocationMsg(msg, mac); bus.makeTargetServiceIdByResourceUuid(msg, L3NetworkConstant.SERVICE_ID, l3NetworkUuid); msg.setAllocateStrategy(stratgey); MessageReply reply = bus.call(msg); if (!reply.isSuccess()) { throw new FlowException(reply.getError()); } AllocateIpReply areply = (AllocateIpReply) reply; return areply.getIpInventory(); }
List<MessageReply> replies = bus.call(msgs); for (MessageReply r : replies) { if (!r.isSuccess()) {
@Override public void beforeChangeClusterState(ClusterInventory inventory, ClusterStateEvent event, ClusterState nextState) { /* * given changing cluster state is working simultaneously, we change host state one by one * in order to avoid thread pool exhausted */ if (!event.toString().equals(ClusterStateEvent.disable.toString()) && !event.toString().equals(ClusterStateEvent.enable.toString())) { logger.debug("Unsupport ClusterStateEvent: " + event + ", won't propgate to extensions of host"); return; } HostStateEvent hostEvent = HostStateEvent.valueOf(event.toString()); List<HostVO> vos = findHostUnderClusterByUuid(inventory.getUuid()); if (!vos.isEmpty()) { for (HostVO h : vos) { if (h.getState() == HostState.Maintenance || h.getState() == HostState.PreMaintenance) { continue; } ChangeHostStateMsg msg = new ChangeHostStateMsg(h.getUuid(), hostEvent.toString()); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, h.getUuid()); ChangeHostStateReply r = (ChangeHostStateReply) bus.call(msg); if (!r.isSuccess()) { logger.warn(String.format("Failed to change host[uuid: %s] state(%s) by event(%s), %s", h.getUuid(), h.getState(), hostEvent, r.getError())); } else { logger.debug(String.format("Successfully changed host[uuid: %s] state(%s) by event(%s), new state is %s", h.getUuid(), h.getState(), hostEvent, r.getInventory().getState())); } } } }
bus.call(msgs);
@Override protected void run(Map tokens, Object data) { PrimaryStorageCanonicalEvent.PrimaryStorageHostStatusChangeData d = (PrimaryStorageCanonicalEvent.PrimaryStorageHostStatusChangeData)data; PrimaryStorageStatus nfsStatus = Q.New(PrimaryStorageVO.class) .eq(PrimaryStorageVO_.uuid, d.getPrimaryStorageUuid()) .eq(PrimaryStorageVO_.type, NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE) .select(PrimaryStorageVO_.status) .findValue(); boolean recoverConnection = d.getNewStatus() == PrimaryStorageHostStatus.Connected && d.getOldStatus() != PrimaryStorageHostStatus.Connected; if (nfsStatus == null || !recoverConnection) { return; } logger.debug(String.format("NFS[uuid:%s] recover connection to host[uuid:%s]", d.getPrimaryStorageUuid(), d.getHostUuid())); if (nfsStatus != PrimaryStorageStatus.Connected) { // use sync call here to make sure the NFS primary storage connected before continue to the next step ChangePrimaryStorageStatusMsg cmsg = new ChangePrimaryStorageStatusMsg(); cmsg.setPrimaryStorageUuid(d.getPrimaryStorageUuid()); cmsg.setStatus(PrimaryStorageStatus.Connected.toString()); bus.makeTargetServiceIdByResourceUuid(cmsg, PrimaryStorageConstant.SERVICE_ID, d.getPrimaryStorageUuid()); bus.call(cmsg); logger.debug(String.format("connect nfs[uuid:%s] completed", d.getPrimaryStorageUuid())); } recalculateCapacity(d.getPrimaryStorageUuid()); } });
private void unmount(PrimaryStorageInventory inv, String hostUuid) { UnmountCmd cmd = new UnmountCmd(); cmd.setUuid(inv.getUuid()); cmd.setMountPath(inv.getMountPath()); cmd.setUrl(inv.getUrl()); KVMHostSyncHttpCallMsg msg = new KVMHostSyncHttpCallMsg(); msg.setCommand(cmd); msg.setPath(UNMOUNT_PRIMARY_STORAGE_PATH); msg.setHostUuid(hostUuid); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, hostUuid); MessageReply reply = bus.call(msg); if (!reply.isSuccess()) { throw new OperationFailureException(reply.getError()); } AgentResponse rsp = ((KVMHostSyncHttpCallReply) reply).toResponse(AgentResponse.class); if (!rsp.isSuccess()) { String err = String.format("Unable to unmount nfs primary storage[uuid:%s] on kvm host[uuid:%s], because %s", inv.getUuid(), hostUuid, rsp.getError()); logger.warn(err); } else { String info = String.format("Successfully unmount nfs primary storage[uuid:%s] on kvm host[uuid:%s]", inv.getUuid(), hostUuid); logger.debug(info); nfsFactory.updateNfsHostStatus(inv.getUuid(), hostUuid, PrimaryStorageHostStatus.Disconnected); } }
@Override void handle(BackupVolumeSnapshotFromPrimaryStorageToBackupStorageMsg msg, final ReturnValueCompletion<BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply> completion) { VolumeSnapshotInventory sinv = msg.getSnapshot(); String bsUuid = msg.getBackupStorage().getUuid(); // Get the backup storage install path BackupStorageAskInstallPathMsg bmsg = new BackupStorageAskInstallPathMsg(); bmsg.setImageMediaType(VolumeSnapshotVO.class.getSimpleName()); bmsg.setBackupStorageUuid(msg.getBackupStorage().getUuid()); bmsg.setImageUuid(sinv.getUuid()); bus.makeTargetServiceIdByResourceUuid(bmsg, BackupStorageConstant.SERVICE_ID, msg.getBackupStorage().getUuid()); MessageReply br = bus.call(bmsg); if (!br.isSuccess()) { completion.fail(br.getError()); return; } final String installPath = ((BackupStorageAskInstallPathReply) br).getInstallPath(); BackupStorageKvmUploader uploader = getBackupStorageKvmUploader(bsUuid); uploader.uploadBits(null, installPath, sinv.getPrimaryStorageInstallPath(), new ReturnValueCompletion<String>(completion) { @Override public void success(String bsPath) { BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply reply = new BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply(); reply.setBackupStorageInstallPath(bsPath); completion.success(reply); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); }
@Override public void preMigrateVm(VmInstanceInventory inv, String destHostUuid) { if (!needLink(inv)) { return; } FusionstorQueryCmd cmd = new FusionstorQueryCmd(); cmd.query = "query"; KVMHostAsyncHttpCallMsg msg = new KVMHostAsyncHttpCallMsg(); msg.setCommand(cmd); msg.setPath(KVM_FUSIONSTOR_QUERY_PATH); msg.setHostUuid(destHostUuid); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, destHostUuid); MessageReply reply = bus.call(msg); if (!reply.isSuccess()) { throw new OperationFailureException(reply.getError()); } KVMHostAsyncHttpCallReply r = reply.castReply(); FusionstorQueryRsp rsp = r.toResponse(FusionstorQueryRsp.class); if (!rsp.isSuccess()) { throw new OperationFailureException(operr(rsp.getError())); } return; }
@Override void handle(BackupVolumeSnapshotFromPrimaryStorageToBackupStorageMsg msg, String hostUuid, final ReturnValueCompletion<BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply> completion) { VolumeSnapshotInventory sp = msg.getSnapshot(); LocalStorageBackupStorageMediator m = localStorageFactory.getBackupStorageMediator(KVMConstant.KVM_HYPERVISOR_TYPE, msg.getBackupStorage().getType()); BackupStorageAskInstallPathMsg bmsg = new BackupStorageAskInstallPathMsg(); bmsg.setImageMediaType(VolumeSnapshotVO.class.getSimpleName()); bmsg.setBackupStorageUuid(msg.getBackupStorage().getUuid()); bmsg.setImageUuid(sp.getUuid()); bus.makeTargetServiceIdByResourceUuid(bmsg, BackupStorageConstant.SERVICE_ID, msg.getBackupStorage().getUuid()); MessageReply br = bus.call(bmsg); if (!br.isSuccess()) { completion.fail(br.getError()); return; } final String installPath = ((BackupStorageAskInstallPathReply) br).getInstallPath(); m.uploadBits(sp.getUuid(), getSelfInventory(), msg.getBackupStorage(), installPath, sp.getPrimaryStorageInstallPath(), hostUuid, new ReturnValueCompletion<String>(completion) { @Override public void success(String installPath) { BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply reply = new BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply(); reply.setBackupStorageInstallPath(installPath); completion.success(reply); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); }
ask.setImageMediaType(paramIn.getImage().getMediaType()); bus.makeTargetServiceIdByResourceUuid(ask, BackupStorageConstant.SERVICE_ID, paramIn.getBackupStorageUuid()); MessageReply ar = bus.call(ask); if (!ar.isSuccess()) { trigger.fail(ar.getError());
ask.setImageMediaType(paramIn.getImage().getMediaType()); bus.makeTargetServiceIdByResourceUuid(ask, BackupStorageConstant.SERVICE_ID, paramIn.getBackupStorageUuid()); MessageReply ar = bus.call(ask); if (!ar.isSuccess()) { trigger.fail(ar.getError());
ask.setImageMediaType(paramIn.getImage().getMediaType()); bus.makeTargetServiceIdByResourceUuid(ask, BackupStorageConstant.SERVICE_ID, paramIn.getBackupStorageUuid()); MessageReply ar = bus.call(ask); if (!ar.isSuccess()) { trigger.fail(ar.getError());
ask.setImageMediaType(paramIn.getImage().getMediaType()); bus.makeTargetServiceIdByResourceUuid(ask, BackupStorageConstant.SERVICE_ID, paramIn.getBackupStorageUuid()); MessageReply ar = bus.call(ask); if (!ar.isSuccess()) { trigger.fail(ar.getError());
ask.setImageUuid(paramIn.getImage().getUuid()); bus.makeTargetServiceIdByResourceUuid(ask, BackupStorageConstant.SERVICE_ID, paramIn.getBackupStorageUuid()); MessageReply areply = bus.call(ask); if (!areply.isSuccess()) { trigger.fail(areply.getError());