Esempio n. 1
0
  public void deleteUser(String user) throws ApiSenderException {
    DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
    UserInventory u = users.get(user);
    DebugUtils.Assert(u != null, String.format("cannot find user[%s]", user));

    api.deleteUser(u.getUuid(), accountSession);
  }
Esempio n. 2
0
  public void deletePolicy(String policy) throws ApiSenderException {
    DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
    PolicyInventory p = policies.get(policy);
    DebugUtils.Assert(p != null, String.format("cannot find policy[%s]", policy));

    api.deletePolicy(p.getUuid(), accountSession);
  }
Esempio n. 3
0
 public void removeUserFromGroup(String user, String group) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
   UserInventory u = users.get(user);
   UserGroupInventory g = groups.get(group);
   DebugUtils.Assert(u != null, String.format("cannot find user[%s]", user));
   DebugUtils.Assert(g != null, String.format("cannot find group[%s]", group));
   api.removeUserFromGroup(u.getUuid(), g.getUuid(), accountSession);
 }
Esempio n. 4
0
 public void detachPolicyFromGroup(String group, String policy) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
   PolicyInventory p = policies.get(policy);
   DebugUtils.Assert(p != null, String.format("cannot find policy[%s]", policy));
   UserGroupInventory g = groups.get(group);
   DebugUtils.Assert(g != null, String.format("cannot find group[%s]", group));
   api.detachPolicyFromGroup(g.getUuid(), p.getUuid(), accountSession);
 }
Esempio n. 5
0
 public void detachPolicyFromUser(String user, String policy) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
   UserInventory u = users.get(user);
   DebugUtils.Assert(u != null, String.format("cannot find user[%s]", user));
   PolicyInventory p = policies.get(policy);
   DebugUtils.Assert(p != null, String.format("cannot find policy[%s]", policy));
   api.detachPolicyFromUser(u.getUuid(), p.getUuid(), accountSession);
 }
  @Override
  public void run(FlowTrigger trigger, Map data) {
    PrimaryStorageAllocationSpec spec =
        (PrimaryStorageAllocationSpec) data.get(AllocatorParams.SPEC);
    List<PrimaryStorageVO> candidates =
        (List<PrimaryStorageVO>) data.get(AllocatorParams.CANDIDATES);
    DebugUtils.Assert(
        candidates != null && !candidates.isEmpty(),
        "PrimaryStorageTagAllocatorFlow cannot be the first element in allocator chain");

    List<SystemTagVO> tvos = null;
    if (spec.getVmInstanceUuid() != null) {
      SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class);
      q.add(SystemTagVO_.resourceType, Op.EQ, VmInstanceVO.class.getSimpleName());
      q.add(SystemTagVO_.resourceUuid, Op.EQ, spec.getVmInstanceUuid());
      tvos = q.list();
    } else if (spec.getDiskOfferingUuid() != null) {
      SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class);
      q.add(SystemTagVO_.resourceType, Op.EQ, DiskOfferingVO.class.getSimpleName());
      q.add(SystemTagVO_.resourceUuid, Op.EQ, spec.getDiskOfferingUuid());
      tvos = q.list();
    }

    if (tvos != null && !tvos.isEmpty()) {
      candidates = callTagExtensions(SystemTagInventory.valueOf(tvos), candidates);
      data.put(AllocatorParams.CANDIDATES, candidates);
    }

    trigger.next();
  }
Esempio n. 7
0
 public AccountInventory useAccount(String name) throws ApiSenderException {
   SimpleQuery<AccountVO> q = dbf.createQuery(AccountVO.class);
   q.add(AccountVO_.name, Op.EQ, name);
   AccountVO vo = q.find();
   DebugUtils.Assert(vo != null, String.format("cannot find account[name:%s]", name));
   account = AccountInventory.valueOf(vo);
   accountSession = api.loginByAccount(name, vo.getPassword());
   return account;
 }
Esempio n. 8
0
  @Transactional
  private void updateCapacity(long total, long avail) {
    PrimaryStorageCapacityVO cvo =
        dbf.getEntityManager()
            .find(PrimaryStorageCapacityVO.class, self.getUuid(), LockModeType.PESSIMISTIC_WRITE);
    DebugUtils.Assert(
        cvo != null,
        String.format("how can there is no PrimaryStorageCapacityVO[uuid:%s]", self.getUuid()));

    cvo.setTotalPhysicalCapacity(total);
    cvo.setAvailablePhysicalCapacity(avail);
    dbf.getEntityManager().merge(cvo);
  }
Esempio n. 9
0
 public UserGroupInventory createGroup(String name) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createGroup()");
   UserGroupInventory g = api.createGroup(account.getUuid(), name, accountSession);
   groups.put(name, g);
   return g;
 }
Esempio n. 10
0
 public UserInventory createUser(String name, String password) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createUser()");
   UserInventory u = api.createUser(account.getUuid(), name, password, accountSession);
   users.put(name, u);
   return u;
 }
Esempio n. 11
0
 public PolicyInventory createPolicy(String name, List<Statement> s) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
   PolicyInventory p = api.createPolicy(name, s, accountSession);
   policies.put(p.getName(), p);
   return p;
 }
Esempio n. 12
0
 public SessionInventory accountLogin(String name, String password) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
   return api.loginByAccount(name, password);
 }
Esempio n. 13
0
 public void deleteGroup(String group) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
   UserGroupInventory g = groups.get(group);
   DebugUtils.Assert(g != null, String.format("cannot find group[%s]", group));
   api.deleteGroup(g.getUuid(), accountSession);
 }
Esempio n. 14
0
 public void resetAccountPassword(String password) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
   api.resetAccountPassword(account.getUuid(), password, accountSession);
 }
Esempio n. 15
0
 public void attachPoliciesToUser(String user, List<String> puuids) throws ApiSenderException {
   DebugUtils.Assert(account != null, "please call createAccount() before createPolicy()");
   UserInventory u = users.get(user);
   DebugUtils.Assert(u != null, String.format("cannot find user[%s]", user));
   api.attachPolicesToUser(u.getUuid(), puuids, accountSession);
 }
Esempio n. 16
0
  @Transactional(readOnly = true)
  private List<VmInstanceVO> getCandidateVmForAttaching(String accountUuid) {
    List<String> vmUuids =
        acntMgr.getResourceUuidsCanAccessByAccount(accountUuid, VmInstanceVO.class);

    if (vmUuids != null && vmUuids.isEmpty()) {
      return new ArrayList<VmInstanceVO>();
    }

    TypedQuery<VmInstanceVO> q = null;
    String sql;
    if (vmUuids == null) {
      // all vms
      if (self.getStatus() == VolumeStatus.Ready) {
        sql =
            "select vm from VmInstanceVO vm, PrimaryStorageClusterRefVO ref, VolumeVO vol where vm.state in (:vmStates) and vol.uuid = :volUuid and vm.hypervisorType in (:hvTypes) and vm.clusterUuid = ref.clusterUuid and ref.primaryStorageUuid = vol.primaryStorageUuid group by vm.uuid";
        q = dbf.getEntityManager().createQuery(sql, VmInstanceVO.class);
        q.setParameter("volUuid", self.getUuid());
        List<String> hvTypes =
            VolumeFormat.valueOf(self.getFormat())
                .getHypervisorTypesSupportingThisVolumeFormatInString();
        q.setParameter("hvTypes", hvTypes);
      } else if (self.getStatus() == VolumeStatus.NotInstantiated) {
        sql = "select vm from VmInstanceVO vm where vm.state in (:vmStates) group by vm.uuid";
        q = dbf.getEntityManager().createQuery(sql, VmInstanceVO.class);
      } else {
        DebugUtils.Assert(
            false, String.format("should not reach here, volume[uuid:%s]", self.getUuid()));
      }
    } else {
      if (self.getStatus() == VolumeStatus.Ready) {
        sql =
            "select vm from VmInstanceVO vm, PrimaryStorageClusterRefVO ref, VolumeVO vol where vm.uuid in (:vmUuids) and vm.state in (:vmStates) and vol.uuid = :volUuid and vm.hypervisorType in (:hvTypes) and vm.clusterUuid = ref.clusterUuid and ref.primaryStorageUuid = vol.primaryStorageUuid group by vm.uuid";
        q = dbf.getEntityManager().createQuery(sql, VmInstanceVO.class);
        q.setParameter("volUuid", self.getUuid());
        List<String> hvTypes =
            VolumeFormat.valueOf(self.getFormat())
                .getHypervisorTypesSupportingThisVolumeFormatInString();
        q.setParameter("hvTypes", hvTypes);
      } else if (self.getStatus() == VolumeStatus.NotInstantiated) {
        sql =
            "select vm from VmInstanceVO vm where vm.uuid in (:vmUuids) and vm.state in (:vmStates) group by vm.uuid";
        q = dbf.getEntityManager().createQuery(sql, VmInstanceVO.class);
      } else {
        DebugUtils.Assert(
            false, String.format("should not reach here, volume[uuid:%s]", self.getUuid()));
      }

      q.setParameter("vmUuids", vmUuids);
    }

    q.setParameter("vmStates", Arrays.asList(VmInstanceState.Running, VmInstanceState.Stopped));
    List<VmInstanceVO> vms = q.getResultList();
    if (vms.isEmpty()) {
      return vms;
    }

    VolumeInventory vol = getSelfInventory();
    for (VolumeGetAttachableVmExtensionPoint ext :
        pluginRgty.getExtensionList(VolumeGetAttachableVmExtensionPoint.class)) {
      vms = ext.returnAttachableVms(vol, vms);
    }

    return vms;
  }
Esempio n. 17
0
 public Map<String, List<String>> getTags(List<String> resourceUuids) {
   DebugUtils.Assert(!resourceUuids.isEmpty(), "how can you pass an empty resourceUuids");
   return getTags(resourceUuids, resourceClass);
 }