public static ZoneInventory valueOf(ZoneVO vo) { ZoneInventory inv = new ZoneInventory(); inv.setName(vo.getName()); inv.setDescription(vo.getDescription()); inv.setUuid(vo.getUuid()); inv.setState(vo.getState().toString()); inv.setType(vo.getType()); inv.setCreateDate(vo.getCreateDate()); inv.setLastOpDate(vo.getLastOpDate()); return inv; }
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()); bus.publish(evt); }
protected void handle(APIChangeZoneStateMsg msg) { APIChangeZoneStateEvent evt = new APIChangeZoneStateEvent(msg.getId()); ZoneStateEvent stateEvt = ZoneStateEvent.valueOf(msg.getStateEvent()); try { extpEmitter.preChange(self, stateEvt); } catch (ZoneException e) { evt.setError(err(SysErrors.CHANGE_RESOURCE_STATE_ERROR, e.getMessage())); bus.publish(evt); return; } ZoneState formerState = self.getState(); extpEmitter.beforeChange(self, stateEvt); ZoneState next = AbstractZone.getNextState(self.getState(), stateEvt); self.setState(next); self = dbf.updateAndRefresh(self); extpEmitter.afterChange(self, stateEvt, formerState); evt.setInventory(ZoneInventory.valueOf(self)); logger.debug(String.format("Changed state of zone[uuid:%s] from %s to %s by event %s", self.getUuid(), formerState, self.getState(), stateEvt)); bus.publish(evt); }
void beforeChange(ZoneVO vo, final ZoneStateEvent event) { final ZoneInventory zinv = ZoneInventory.valueOf(vo); final ZoneState next = AbstractZone.getNextState(vo.getState(), event); CollectionUtils.safeForEach(changeExts, new ForEachFunction<ZoneChangeStateExtensionPoint>() { @Override public void run(ZoneChangeStateExtensionPoint arg) { arg.beforeChangeZoneState(zinv, event, next); } }); }
private void handle(APIUpdateZoneMsg msg) { boolean update = false; if (msg.getName() != null) { self.setName(msg.getName()); update = true; } if (msg.getDescription() != null) { self.setDescription(msg.getDescription()); update = true; } if (update) { self = dbf.updateAndRefresh(self); } APIUpdateZoneEvent evt = new APIUpdateZoneEvent(msg.getId()); evt.setInventory(ZoneInventory.valueOf(self)); bus.publish(evt); }
private void passThrough(ZoneMessage msg) { ZoneVO vo = dbf.findByUuid(msg.getZoneUuid(), ZoneVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { ZoneEO eo = dbf.findByUuid(msg.getZoneUuid(), ZoneEO.class); vo = ObjectUtils.newAndCopy(eo, ZoneVO.class); } if (vo == null) { ErrorCode err = err(SysErrors.RESOURCE_NOT_FOUND, "unable to find zone[uuid:%s], it may have been deleted", msg.getZoneUuid()); bus.replyErrorByMessageType((Message)msg, err); return; } ZoneFactory factory = this.getZoneFactory(ZoneType.valueOf(vo.getType())); Zone zone = factory.getZone(vo); zone.handleMessage((Message)msg); }
void preChange(ZoneVO vo, ZoneStateEvent event) throws ZoneException { ZoneInventory zinv = ZoneInventory.valueOf(vo); ZoneState next = AbstractZone.getNextState(vo.getState(), event); for (ZoneChangeStateExtensionPoint extp : changeExts) { try { extp.preChangeZoneState(zinv, event, next); } catch (ZoneException ze) { logger.debug(String.format("Extension: %s refused zone change state operation[ZoneStateEvent:%s] because %s", extp.getClass() .getCanonicalName(), event, ze.getMessage())); throw ze; } catch (Exception e) { logger.warn("Exception happened while calling " + extp.getClass().getCanonicalName() + ".preChangeZoneState(), " + "zone name: " + zinv.getName() + " uuid: " + zinv.getUuid(), e); } } }