protected void handle(final APIAttachPrimaryStorageToClusterMsg msg) { thdf.chainSubmit( new ChainTask(msg) { @Override public String getSyncSignature() { return getSyncId(); } @Override public void run(final SyncTaskChain chain) { attachCluster( msg, new NoErrorCompletion(msg, chain) { @Override public void done() { chain.next(); } }); } @Override public String getName() { return String.format( "attach-primary-storage-%s-to-cluster-%s", self.getUuid(), msg.getClusterUuid()); } }); }
private void handle(final DetachPrimaryStorageFromClusterMsg msg) { final DetachPrimaryStorageFromClusterReply reply = new DetachPrimaryStorageFromClusterReply(); thdf.chainSubmit( new ChainTask(msg) { @Override public String getSyncSignature() { return getSyncId(); } @Override public void run(final SyncTaskChain chain) { extpEmitter.beforeDetach(self, msg.getClusterUuid()); detachHook( msg.getClusterUuid(), new Completion(msg, chain) { @Override public void success() { SimpleQuery<PrimaryStorageClusterRefVO> q = dbf.createQuery(PrimaryStorageClusterRefVO.class); q.add(PrimaryStorageClusterRefVO_.clusterUuid, Op.EQ, msg.getClusterUuid()); q.add( PrimaryStorageClusterRefVO_.primaryStorageUuid, Op.EQ, msg.getPrimaryStorageUuid()); List<PrimaryStorageClusterRefVO> refs = q.list(); dbf.removeCollection(refs, PrimaryStorageClusterRefVO.class); self = dbf.reload(self); extpEmitter.afterDetach(self, msg.getClusterUuid()); logger.debug( String.format( "successfully detached primary storage[name: %s, uuid:%s]", self.getName(), self.getUuid())); bus.reply(msg, reply); chain.next(); } @Override public void fail(ErrorCode errorCode) { extpEmitter.failToDetach(self, msg.getClusterUuid()); logger.warn(errorCode.toString()); reply.setError( errf.instantiateErrorCode(PrimaryStorageErrors.DETACH_ERROR, errorCode)); bus.reply(msg, reply); chain.next(); } }); } @Override public String getName() { return String.format( "detach-primary-storage-%s-from-%s", self.getUuid(), msg.getClusterUuid()); } }); }
@Test public void test() throws InterruptedException { for (int i = 0; i < threadNum; i++) { Tester t = new Tester(i); thdf.chainSubmit(t); } latch.await(2, TimeUnit.MINUTES); Assert.assertEquals(threadNum, res.size()); }
@Test public void test() throws InterruptedException { for (int i = 0; i < threadNum; i++) { Tester t = new Tester(i); thdf.chainSubmit(t); } latch.await(2, TimeUnit.MINUTES); int si = -1; for (Integer index : res) { logger.debug(String.format("last: %s, next: %s", si, index)); Assert.assertTrue(index > si); si = index; } }
private void startLogThread() { thdf.submit( new Task<Void>() { @Override public String getName() { return "log-thread"; } @Override public Void call() throws Exception { consume(); return null; } }); }
private void handle(final APICreateVolumeSnapshotMsg msg) { thdf.chainSubmit( new ChainTask(msg) { @Override public String getSyncSignature() { return String.format("create-snapshot-for-volume-%s", self.getUuid()); } @Override public void run(final SyncTaskChain chain) { CreateVolumeSnapshotMsg cmsg = new CreateVolumeSnapshotMsg(); cmsg.setName(msg.getName()); cmsg.setDescription(msg.getDescription()); cmsg.setResourceUuid(msg.getResourceUuid()); cmsg.setAccountUuid(msg.getSession().getAccountUuid()); cmsg.setVolumeUuid(msg.getVolumeUuid()); bus.makeLocalServiceId(cmsg, VolumeSnapshotConstant.SERVICE_ID); bus.send( cmsg, new CloudBusCallBack(chain) { @Override public void run(MessageReply reply) { APICreateVolumeSnapshotEvent evt = new APICreateVolumeSnapshotEvent(msg.getId()); if (reply.isSuccess()) { CreateVolumeSnapshotReply creply = (CreateVolumeSnapshotReply) reply; evt.setInventory(creply.getInventory()); tagMgr.createTagsFromAPICreateMessage( msg, creply.getInventory().getUuid(), VolumeSnapshotVO.class.getSimpleName()); } else { evt.setErrorCode(reply.getError()); } bus.publish(evt); chain.next(); } }); } @Override public String getName() { return String.format("create-snapshot-for-volume-%s", self.getUuid()); } }); }
private void handle(final ConnectBackupStorageMsg msg) { thdf.chainSubmit( new ChainTask(msg) { @Override public String getSyncSignature() { return String.format("connect-backup-storage-%s", self.getUuid()); } @Override public void run(final SyncTaskChain chain) { final ConnectBackupStorageReply reply = new ConnectBackupStorageReply(); changeStatus(BackupStorageStatus.Connecting); connectHook( msg.isNewAdd(), new Completion(msg, chain) { @Override public void success() { self = dbf.reload(self); changeStatus(BackupStorageStatus.Connected); tracker.track(self.getUuid()); bus.reply(msg, reply); chain.next(); } @Override public void fail(ErrorCode errorCode) { if (!msg.isNewAdd()) { changeStatus(BackupStorageStatus.Disconnected); } reply.setError(errorCode); bus.reply(msg, reply); chain.next(); } }); } @Override public String getName() { return getSyncSignature(); } }); }
private void handle(final VolumeDeletionMsg msg) { thdf.chainSubmit( new ChainTask() { @Override public String getSyncSignature() { return getName(); } @Override public void run(final SyncTaskChain chain) { self = dbf.reload(self); if (self.getStatus() == VolumeStatus.Deleted) { // the volume has been deleted // we run into this case because the cascading framework // will send duplicate messages when deleting a vm as the cascading // framework has no knowledge about if the volume has been deleted VolumeDeletionReply reply = new VolumeDeletionReply(); bus.reply(msg, reply); chain.next(); return; } deleteVolume( msg, new NoErrorCompletion(chain) { @Override public void done() { chain.next(); } }); } @Override public String getName() { return String.format("delete-volume-%s", self.getUuid()); } }); }
protected void changeStatus( final BackupStorageStatus status, final NoErrorCompletion completion) { thdf.syncSubmit( new SyncTask<Void>() { private String name = String.format("backupstorage-%s-change-status", self.getUuid()); @Override public String getSyncSignature() { return name; } @Override public int getSyncLevel() { return 1; } @Override public String getName() { return name; } @Override public Void call() throws Exception { if (status == self.getStatus()) { completion.done(); return null; } changeStatus(status); logger.debug( String.format( "backup storage[uuid:%s, name:%s] change status from %s to %s", self.getUuid(), self.getName(), self.getStatus(), status)); completion.done(); return null; } }); }