Exemplo n.º 1
0
  @Override
  public Resource delete0(final CallStruct call) throws Exception {
    super.delete0(call);
    final AccountType ac = call.getAc();
    final String name = call.getPhysicalId();

    HibernateUtil.withNewSession(
        new Operation<Object>() {

          @Override
          public Object ex(final Session s, final Object... args) throws Exception {

            final CacheSecurityGroupBean securityGroup =
                EcacheUtil.getCacheSecurityGroupBean(s, ac.getId(), name);

            // Validate Exists
            if (securityGroup == null) {
              throw ElasticacheFaults.CacheSecurityGroupNotFound();
            }

            final List<CacheClusterBean> ccbs =
                EcacheUtil.selectCacheClusterBean(s, ac.getId(), null);
            boolean used = false;
            for (final CacheClusterBean ccb : ccbs) {
              if (ccb.getSecurityGroups().contains(name)) {
                used = true;
                break;
              }
            }
            if (used) {
              throw ElasticacheFaults.InvalidCacheSecurityGroupState();
            }

            EcacheUtil.deleteSecurityGroupBean(s, ac, name);
            return null;
          }
        });
    logger.debug("SecurityGroup deleted " + name);
    return null;
  }
Exemplo n.º 2
0
  @Override
  public CFType create0(final CallStruct call) throws Exception {
    final AccountType ac = call.getAc();
    final String name = call.getName();
    final String description = (String) call.getProperty("Description");

    HibernateUtil.withNewSession(
        new Operation<CacheSecurityGroupBean>() {

          @Override
          public CacheSecurityGroupBean ex(final Session s, final Object... args) throws Exception {
            final CacheSecurityGroupBean secGrp =
                EcacheUtil.createSecurityGroup(
                    s, ac.getId(), name, description, call.getStackId(), name);
            return secGrp;
          }
        });

    final SecurityGroupType ret = new SecurityGroupType();
    ret.setName(name);
    return ret;
  }