@Override
  public Object create(String type, ApiRequest request, ResourceManager next) {
    Service service = request.proxyRequestObject(Service.class);

    validateSelectorOnlyService(request, service);
    return super.create(type, request, next);
  }
示例#2
0
  @Override
  protected Object createInternal(String type, ApiRequest request) {
    if (!StringUtils.equals(ADConstants.CONFIG, request.getType())) {
      return null;
    }

    LDAPConstants config = request.proxyRequestObject(LDAPConstants.class);
    LDAPUtils.validateConfig(config);
    return updateCurrentConfig(config);
  }
示例#3
0
  @Override
  public Object create(String type, ApiRequest request, ResourceManager next) {
    ServiceEvent event = request.proxyRequestObject(ServiceEvent.class);

    /* Will never return null, MissingRequired will be thrown if missing */
    Agent agent = getAgent();
    if (agent == null) {
      throw new ClientVisibleException(ResponseCodes.FORBIDDEN, VERIFY_AGENT);
    }

    HealthcheckInstanceHostMap healthcheckInstanceHostMap = null;
    String[] splitted = event.getHealthcheckUuid().split("_");
    if (splitted.length > 2) {
      healthcheckInstanceHostMap = serviceDao.getHealthCheckInstanceUUID(splitted[0], splitted[1]);
    } else {
      healthcheckInstanceHostMap =
          objectManager.findOne(
              HealthcheckInstanceHostMap.class, ObjectMetaDataManager.UUID_FIELD, splitted[0]);
    }

    if (healthcheckInstanceHostMap == null) {
      throw new ClientVisibleException(ResponseCodes.FORBIDDEN, VERIFY_AGENT);
    }

    HealthcheckInstance healthcheckInstance =
        objectManager.loadResource(
            HealthcheckInstance.class, healthcheckInstanceHostMap.getHealthcheckInstanceId());

    if (healthcheckInstance == null) {
      return null;
    }
    Long resourceAccId =
        DataAccessor.fromDataFieldOf(agent)
            .withKey(AgentConstants.DATA_AGENT_RESOURCES_ACCOUNT_ID)
            .as(Long.class);

    if (!healthcheckInstanceHostMap.getAccountId().equals(resourceAccId)) {
      throw new ClientVisibleException(ResponseCodes.FORBIDDEN, VERIFY_AGENT);
    }

    event.setInstanceId(healthcheckInstance.getInstanceId());
    event.setHealthcheckInstanceId(healthcheckInstance.getId());
    event.setHostId(healthcheckInstanceHostMap.getHostId());

    return super.create(type, request, next);
  }
  @Override
  public Object create(String type, ApiRequest request, ResourceManager next) {
    Environment env = request.proxyRequestObject(Environment.class);

    if (env.getName().startsWith("-") || env.getName().endsWith("-")) {
      ValidationErrorCodes.throwValidationError(ValidationErrorCodes.INVALID_CHARACTERS, "name");
    }

    ResourceManager rm = locator.getResourceManagerByType(type);

    Map<Object, Object> criteria = new HashMap<>();
    criteria.put(ObjectMetaDataManager.NAME_FIELD, env.getName());
    criteria.put(ObjectMetaDataManager.REMOVED_FIELD, new Condition(ConditionType.NULL));
    List<?> existingEnv = rm.list(type, criteria, null);
    if (!existingEnv.isEmpty()) {
      ValidationErrorCodes.throwValidationError(ValidationErrorCodes.NOT_UNIQUE, "name");
    }
    return super.create(type, request, next);
  }