public static List<ZoneInventory> valueOf(Collection<ZoneVO> vos) { List<ZoneInventory> invs = new ArrayList<ZoneInventory>(vos.size()); for (ZoneVO vo : vos) { invs.add(ZoneInventory.valueOf(vo)); } return invs; }
void afterChange(ZoneVO vo, final ZoneStateEvent event, final ZoneState previousState) { final ZoneInventory zinv = ZoneInventory.valueOf(vo); CollectionUtils.safeForEach(changeExts, new ForEachFunction<ZoneChangeStateExtensionPoint>() { @Override public void run(ZoneChangeStateExtensionPoint arg) { arg.afterChangeZoneState(zinv, event, previousState); } }); }
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(APIGetZoneMsg msg) { APIGetZoneReply reply = new APIGetZoneReply(); if (msg.getUuid() != null) { ZoneVO vo = dbf.findByUuid(msg.getUuid(), ZoneVO.class); reply.setInventories(asList(ZoneInventory.valueOf(vo))); } else { reply.setInventories(ZoneInventory.valueOf(dbf.listAll(ZoneVO.class))); } bus.reply(msg, reply); }
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); } } }
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); }
@Override public void run(MessageReply reply) { if (!reply.isSuccess()) { areply.setError(reply.getError()); } else { AllocateHostDryRunReply re = reply.castReply(); if (!re.getHosts().isEmpty()) { areply.setHosts(re.getHosts()); List<String> clusterUuids = re.getHosts().stream(). map(HostInventory::getClusterUuid).collect(Collectors.toList()); areply.setClusters(ClusterInventory.valueOf(dbf.listByPrimaryKeys(clusterUuids, ClusterVO.class))); List<String> zoneUuids = re.getHosts().stream(). map(HostInventory::getZoneUuid).collect(Collectors.toList()); areply.setZones(ZoneInventory.valueOf(dbf.listByPrimaryKeys(zoneUuids, ZoneVO.class))); } else { areply.setHosts(new ArrayList<>()); areply.setClusters(new ArrayList<>()); areply.setZones(new ArrayList<>()); } } bus.reply(msg, areply); } });
private void handle(ZoneDeletionMsg msg) { ZoneInventory inv = ZoneInventory.valueOf(self); extpEmitter.beforeDelete(inv); deleteHook(); extpEmitter.afterDelete(inv); ZoneDeletionReply reply = new ZoneDeletionReply(); bus.reply(msg, reply); }
protected void handle(APIDeleteZoneMsg msg) { final APIDeleteZoneEvent evt = new APIDeleteZoneEvent(msg.getId()); final String issuer = ZoneVO.class.getSimpleName(); ZoneInventory zinv = ZoneInventory.valueOf(self); final List<ZoneInventory> ctx = Arrays.asList(zinv); FlowChain chain = FlowChainBuilder.newSimpleFlowChain();
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); }
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); }
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); }