private void cleanupUser() {
   Session s = HibernateUtil.getSession();
   s.beginTransaction();
   AccountBean ab = AccountUtil.readAccount(s, accessKey);
   s.delete(ab);
   s.getTransaction().commit();
 }
 private void setupUser() {
   Session s = HibernateUtil.getSession();
   s.beginTransaction();
   AccountBean ab = new AccountBean();
   ab.setName("DNS53_TESTER");
   ab.setAccessKey(accessKey);
   ab.setSecretKey(secretKey);
   ab.setDefSecurityGroups("default");
   ab.setDefZone("DNS53_TEST_DEFAULT_ZONE");
   s.save(ab);
   s.getTransaction().commit();
 }
Пример #3
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;
  }
Пример #4
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;
  }
  /*
  	 * (non-Javadoc)
  	 *
  	 * @see com.msi.tough.query.AbstractProxyAction#
  	protected DescribeDBParameterGroupsActionResultMessage doWork0(DescribeDBParameterGroupsActionRequestMessage req,
  ServiceRequestContext context) throws Exception {

  	 * javax.servlet.http.HttpServletRequest,
  	 * javax.servlet.http.HttpServletResponse, java.util.Map)
  	 */
  @Override
  protected DescribeDBParameterGroupsActionResultMessage doWork0(
      DescribeDBParameterGroupsActionRequestMessage req, ServiceRequestContext context)
      throws Exception {

    DescribeDBParameterGroupsActionResultMessage.Builder resp = null;
    String msg = "";
    final Session sess = HibernateUtil.newSession();
    try {
      sess.beginTransaction();
      final AccountBean ac = context.getAccountBean();
      final long userID = ac.getId();
      final String grpName = req.getDbParameterGroupName();
      final String marker = req.getMarker();
      final int maxRecords = ValidationManager.validateMaxRecords(req.getMaxRecords(), false);

      logger.info(
          "DescribeDBParameterGroups: "
              + " account = "
              + ac.getId()
              + " DBParameterGroupName = "
              + grpName
              + " Marker = "
              + marker
              + " MaxRecords = "
              + maxRecords);

      // select the list of DBParameterGroups.
      final List<RdsDbparameterGroup> result =
          ParameterGroupEntity.selectDBParameterGroups(
              sess, grpName, ac.getId(), marker, maxRecords);

      if (grpName != null && (result == null || result.size() == 0)) {
        throw RDSQueryFaults.DBParameterGroupNotFound();
      }

      // build response document
      final List<DBParameterGroup> grl = new ArrayList<DBParameterGroup>();
      if (result != null) {
        logger.debug(
            result.size() + " DBParameterGroups are selected from custom DBParameterGroups.");
        for (final RdsDbparameterGroup gb : result) {
          grl.add(toDBParameterGroup(gb));
        }
      }
      resp = DescribeDBParameterGroupsActionResultMessage.newBuilder();
      resp.addAllDbParameterGroups(grl);
      sess.getTransaction().commit();
    } catch (final ErrorResponse rde) {
      sess.getTransaction().rollback();
      throw rde;
    } catch (final Exception e) {
      e.printStackTrace();
      sess.getTransaction().rollback();
      msg = "DescribeDBParameterGroups: Class: " + e.getClass() + "Msg:" + e.getMessage();
      logger.error(msg);
      throw RDSQueryFaults.InternalFailure();
    } finally {
      sess.close();
    }
    return resp.buildPartial();
  }