@Override public void changeStateHook(PrimaryStorageStateEvent evt, PrimaryStorageState nextState) { logger.debug(String.format("SimulatorPrimaryStorage[uuid:%s] changes state from %s to %s", self.getUuid(), self.getState(), nextState)); }
void preChange(PrimaryStorageVO vo, PrimaryStorageStateEvent evt) throws PrimaryStorageException { PrimaryStorageState next = AbstractPrimaryStorage.getNextState(vo.getState(), evt); PrimaryStorageInventory inv = PrimaryStorageInventory.valueOf(vo); for (PrimaryStorageChangeStateExtensionPoint extp : changeExts) { try { extp.preChangePrimaryStorageState(inv, evt, next); } catch (PrimaryStorageException pe) { logger.debug(String.format("%s refused to change primary storage[uuid:%s] state from %s to %s because %s", extp.getClass().getCanonicalName(), vo.getUuid(), vo.getState(), next, pe.getMessage()), pe); throw pe; } catch (Exception e) { logger.warn("Exception happened when calling preChangePrimaryStorageState of PrimaryStorageChangeStateExtensionPoint", e); } } }
void beforeChange(PrimaryStorageVO vo, final PrimaryStorageStateEvent evt) { final PrimaryStorageInventory inv = PrimaryStorageInventory.valueOf(vo); final PrimaryStorageState next = AbstractPrimaryStorage.getNextState(vo.getState(), evt); CollectionUtils.safeForEach(changeExts, new ForEachFunction<PrimaryStorageChangeStateExtensionPoint>() { @Override public void run(PrimaryStorageChangeStateExtensionPoint arg) { arg.beforeChangePrimaryStorageState(inv, evt, next); } }); }
public void validate(){ ErrorCode errorCode = new ErrorCode(); errorCode.setCode(PrimaryStorageErrors.ALLOCATE_ERROR.toString()); errorCode.setDescription("Operation is not permitted"); if (forbidOperationWhenPrimaryStorageDisable && self.getState().equals(PrimaryStorageState.Disabled)) { String error = "Operation is not permitted when primary storage status is 'Disabled', please check primary storage status"; errorCode.setDetails(error); } if (forbidOperationWhenPrimaryStorageMaintenance && self.getState().equals(PrimaryStorageState.Maintenance)) { String error = "Operation is not permitted when primary storage status is 'Maintenance', please check primary storage status"; errorCode.setDetails(error); } if (null != errorCode.getDetails()){ throw new OperationFailureException(errorCode); } } }
@Override protected void checkImageIfNeedToDownload(DownloadIsoToPrimaryStorageMsg msg){ logger.debug("check if image exist in disabled primary storage"); if(self.getState() != PrimaryStorageState.Disabled){ return ; } if( !Q.New(ImageCacheVO.class) .eq(ImageCacheVO_.primaryStorageUuid, self.getUuid()) .eq(ImageCacheVO_.imageUuid, msg.getIsoSpec().getInventory().getUuid()) .like(ImageCacheVO_.installUrl, String.format("%%hostUuid://%s%%", msg.getDestHostUuid())) .isExists()){ throw new OperationFailureException(operr( "cannot attach ISO to a primary storage[uuid:%s] which is disabled", self.getUuid())); } }
protected void checkImageIfNeedToDownload(DownloadIsoToPrimaryStorageMsg msg){ logger.debug("check if image exist in disabled primary storage"); if(self.getState() != PrimaryStorageState.Disabled){ return ; } if( !Q.New(ImageCacheVO.class) .eq(ImageCacheVO_.primaryStorageUuid, self.getUuid()) .eq(ImageCacheVO_.imageUuid, msg.getIsoSpec().getInventory().getUuid()) .isExists()){ throw new OperationFailureException(operr( "cannot attach ISO to a primary storage[uuid:%s] which is disabled", self.getUuid())); } }
protected PrimaryStorageInventory(PrimaryStorageVO vo) { setZoneUuid(vo.getZoneUuid()); setCreateDate(vo.getCreateDate()); setDescription(vo.getDescription()); setLastOpDate(vo.getLastOpDate()); setName(vo.getName()); setState(vo.getState().toString()); setType(vo.getType()); setUrl(vo.getUrl()); setUuid(vo.getUuid()); setMountPath(vo.getMountPath()); setStatus(vo.getStatus().toString()); attachedClusterUuids = new ArrayList<String>(vo.getAttachedClusterRefs().size()); for (PrimaryStorageClusterRefVO ref : vo.getAttachedClusterRefs()) { attachedClusterUuids.add(ref.getClusterUuid()); } if (vo.getCapacity() != null) { setTotalCapacity(vo.getCapacity().getTotalCapacity()); setAvailableCapacity(vo.getCapacity().getAvailableCapacity()); setTotalPhysicalCapacity(vo.getCapacity().getTotalPhysicalCapacity()); setAvailablePhysicalCapacity(vo.getCapacity().getAvailablePhysicalCapacity()); setSystemUsedCapacity(vo.getCapacity().getSystemUsedCapacity()); } }
protected void handle(APIChangePrimaryStorageStateMsg msg) { APIChangePrimaryStorageStateEvent evt = new APIChangePrimaryStorageStateEvent(msg.getId()); PrimaryStorageState currState = self.getState(); PrimaryStorageStateEvent event = PrimaryStorageStateEvent.valueOf(msg.getStateEvent()); PrimaryStorageState nextState = AbstractPrimaryStorage.getNextState(currState, event);
private void handle(final APILocalStorageMigrateVolumeMsg msg) { final APILocalStorageMigrateVolumeEvent evt = new APILocalStorageMigrateVolumeEvent(msg.getId()); if (self.getState() == PrimaryStorageState.Disabled) { evt.setError(operr("The primary storage[uuid:%s] is disabled cold migrate is not allowed", msg.getPrimaryStorageUuid())); bus.publish(evt);