private void attachCluster( final APIAttachPrimaryStorageToClusterMsg msg, final NoErrorCompletion completion) { final APIAttachPrimaryStorageToClusterEvent evt = new APIAttachPrimaryStorageToClusterEvent(msg.getId()); try { extpEmitter.preAttach(self, msg.getClusterUuid()); } catch (PrimaryStorageException pe) { evt.setErrorCode( errf.instantiateErrorCode(PrimaryStorageErrors.ATTACH_ERROR, pe.getMessage())); bus.publish(evt); completion.done(); return; } extpEmitter.beforeAttach(self, msg.getClusterUuid()); attachHook( msg.getClusterUuid(), new Completion(msg, completion) { @Override public void success() { PrimaryStorageClusterRefVO ref = new PrimaryStorageClusterRefVO(); ref.setClusterUuid(msg.getClusterUuid()); ref.setPrimaryStorageUuid(self.getUuid()); dbf.persist(ref); self = dbf.reload(self); extpEmitter.afterAttach(self, msg.getClusterUuid()); PrimaryStorageInventory pinv = (PrimaryStorageInventory) invf.valueOf(self); evt.setInventory(pinv); logger.debug( String.format( "successfully attached primary storage[name:%s, uuid:%s]", pinv.getName(), pinv.getUuid())); bus.publish(evt); completion.done(); } @Override public void fail(ErrorCode errorCode) { extpEmitter.failToAttach(self, msg.getClusterUuid()); evt.setErrorCode( errf.instantiateErrorCode(PrimaryStorageErrors.ATTACH_ERROR, errorCode)); bus.publish(evt); completion.done(); } }); }