private ZoneFactory getZoneFactory(ZoneType type) { ZoneFactory factory = zoneFactories.get(type.toString()); if (factory == null) { throw new CloudRuntimeException(String.format("No ZoneFactory of type[%s] found", type)); } return factory; }
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); }
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 = errf.instantiateErrorCode( SysErrors.RESOURCE_NOT_FOUND, String.format( "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); }