/** * ユーザの一覧を取得するコマンド. * * @version 1.0.0 * @author NTT Software Corporation. * <!-- * $Date: 2011-11-28 19:50:40 +0900 (月, 28 11 2011) $ * $Revision: 949 $ * $Author: NTT Software Corporation. $ * --> */ public class SGetAllUsersCommand extends AbstractCloudDriverCommand { private static final VhutLogger logger = VhutLogger.getLogger(SGetAllClustersCommand.class); /** デフォルトコンストラクタ. */ public SGetAllUsersCommand() { operation = CommandOperation.GET_ALL_USERS; } /* * (non-Javadoc) * * @see jp.co.ntts.vhut.command.ICommand#execute() */ @Override public CommandStatus execute() { command.status = CommandStatus.ERROR; try { if (isPrivate) { // プライベートクラウドの処理 result = new ArrayList<CloudUser>(prcDirver.getAllUsers()); } else { // パブリッククラウドの処理 } command.status = CommandStatus.SUCCESS; } catch (Exception e) { command.status = CommandStatus.ERROR; throw new CommandExecutionRuntimeException(operation, command.id, e); } return command.status; } /* * (non-Javadoc) * * @see jp.co.ntts.vhut.command.ICommand#finish() */ @Override public void finish() { try { updateSynchronizedEntiteis(CloudUser.class); } catch (Exception e) { throw new CommandFinishRuntimeException(operation, command.id, e); } } /* (non-Javadoc) * @see jp.co.ntts.vhut.command.ICommand#setParameter(java.io.Serializable[]) */ @Override public void setParameter(Serializable... args) { throw new UnsupportedOperationException(); } }
/** * Vmを起動するコマンド. <br> * * @version 1.0.0 * @author NTT Software Corporation. * <!-- * $Date: 2011-11-28 19:50:40 +0900 (月, 28 11 2011) $ * $Revision: 949 $ * $Author: NTT Software Corporation. $ * --> */ public class SStartVmCommand extends AbstractCloudDriverCommand { private static final VhutLogger logger = VhutLogger.getLogger(SStartVmCommand.class); /** パラメータ保存用のキー */ protected enum Key { /** VMのID */ VM_ID } /** デフォルトコンストラクタ. */ public SStartVmCommand() { operation = CommandOperation.START_VM_SYNC; } /** * コマンド実行時に必要なパラメータを設定します. * * <p>{@link ICommand#init(long)}を用いて生成した後に 引数が必要なコマンドに対して個々の引数を設定するための関数です。 * * @param vmId VMのID */ public void setParameter(Long vmId) { parameter = new EnumMap<Key, Serializable>(Key.class); parameter.put(Key.VM_ID, vmId); } /* * (non-Javadoc) * * @see jp.co.ntts.vhut.command.ICommand#execute() */ @Override public CommandStatus execute() { command.status = CommandStatus.EXECUTING; try { if (isPrivate) { // プライベートクラウドの処理 prcDirver.startVmAsync((Long) parameter.get(Key.VM_ID), command.id); } else { // パブリッククラウドの処理 } setVmStatus(VmStatus.POWERING_UP); command.status = CommandStatus.SUCCESS; } catch (Exception e) { command.status = CommandStatus.ERROR; throw new CommandExecutionRuntimeException(operation, command.id, e); } return command.status; } /* * (non-Javadoc) * * @see jp.co.ntts.vhut.command.ICommand#finish() */ @Override public void finish() { try { setVmStatus(VmStatus.UP); } catch (Exception e) { throw new CommandFinishRuntimeException(operation, command.id, e); } } private boolean setVmStatus(VmStatus status) { Vm vm = jdbcManager.from(Vm.class).id(parameter.get(Key.VM_ID)).getSingleResult(); if (vm != null) { vm.status = status; jdbcManager.update(vm).execute(); return true; } return false; } /* (non-Javadoc) * @see jp.co.ntts.vhut.command.ICommand#setParameter(java.io.Serializable[]) */ @Override public void setParameter(Serializable... args) { parameter = new EnumMap<Key, Serializable>(Key.class); parameter.put(Key.VM_ID, args[0]); } }