private void validateCreateRequests(Set<ServiceRequest> requests, Clusters clusters)
          throws AuthorizationException, AmbariException {

    AmbariMetaInfo ambariMetaInfo = getManagementController().getAmbariMetaInfo();
    Map<String, Set<String>> serviceNames = new HashMap<>();
    Set<String> duplicates = new HashSet<>();

    for (ServiceRequest request : requests) {
      final String clusterName = request.getClusterName();
      final String serviceName = request.getServiceName();
      Validate.notEmpty(clusterName, "Cluster name should be provided when creating a service");
      Validate.notEmpty(serviceName, "Service name should be provided when creating a service");

      if (LOG.isDebugEnabled()) {
        LOG.debug("Received a createService request, clusterName={}, serviceName={}, request={}", clusterName, serviceName, request);
      }

      if(!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, getClusterResourceId(clusterName), RoleAuthorization.SERVICE_ADD_DELETE_SERVICES)) {
        throw new AuthorizationException("The user is not authorized to create services");
      }

      if (!serviceNames.containsKey(clusterName)) {
        serviceNames.put(clusterName, new HashSet<>());
      }

      if (serviceNames.get(clusterName).contains(serviceName)) {
        // throw error later for dup
        duplicates.add(serviceName);
        continue;
      }
      serviceNames.get(clusterName).add(serviceName);

      if (StringUtils.isNotEmpty(request.getDesiredState())) {
        State state = State.valueOf(request.getDesiredState());
        if (!state.isValidDesiredState() || state != State.INIT) {
          throw new IllegalArgumentException("Invalid desired state"
                  + " only INIT state allowed during creation"
                  + ", providedDesiredState=" + request.getDesiredState());
        }
      }

      Cluster cluster;
      try {
        cluster = clusters.getCluster(clusterName);
      } catch (ClusterNotFoundException e) {
        throw new ParentObjectNotFoundException("Attempted to add a service to a cluster which doesn't exist", e);
      }
      try {
        Service s = cluster.getService(serviceName);
        if (s != null) {
          // throw error later for dup
          duplicates.add(serviceName);
          continue;
        }
      } catch (ServiceNotFoundException e) {
        // Expected
      }

      Long desiredRepositoryVersion = request.getDesiredRepositoryVersionId();

      if (null == desiredRepositoryVersion) {
        Set<Long> repoIds = new HashSet<>();

        for (Service service : cluster.getServices().values()) {
          RepositoryVersionEntity serviceRepo = service.getDesiredRepositoryVersion();
          if (null != serviceRepo.getParentId()) {
            repoIds.add(serviceRepo.getParentId());
          } else {
            repoIds.add(serviceRepo.getId());
          }
        }

        LOG.info("{} was not specified; the following repository ids were found: {}",
            SERVICE_DESIRED_REPO_VERSION_ID_PROPERTY_ID, StringUtils.join(repoIds, ','));

        if (CollectionUtils.isEmpty(repoIds)) {
          throw new IllegalArgumentException("No repositories were found for service installation");
        } else if (repoIds.size() > 1) {
          throw new IllegalArgumentException(String.format("%s was not specified, and the cluster " +
              "contains more than one standard-type repository", SERVICE_DESIRED_REPO_VERSION_ID_PROPERTY_ID));
        } else {
          desiredRepositoryVersion = repoIds.iterator().next();
        }
      }

      if (null == desiredRepositoryVersion) {
        throw new IllegalArgumentException(String.format("%s is required when adding a service.", SERVICE_DESIRED_REPO_VERSION_ID_PROPERTY_ID));
      }

      RepositoryVersionEntity repositoryVersion = repositoryVersionDAO.findByPK(desiredRepositoryVersion);

      if (null == repositoryVersion) {
        throw new IllegalArgumentException(String.format("Could not find any repositories defined by %d", desiredRepositoryVersion));
      }

      StackId stackId = repositoryVersion.getStackId();

      request.setResolvedRepository(repositoryVersion);

      if (!ambariMetaInfo.isValidService(stackId.getStackName(),
              stackId.getStackVersion(), request.getServiceName())) {
        throw new IllegalArgumentException("Unsupported or invalid service in stack, clusterName=" + clusterName
                + ", serviceName=" + serviceName + ", stackInfo=" + stackId.getStackId());
      }

      // validate the credential store input provided
      ServiceInfo serviceInfo = ambariMetaInfo.getService(stackId.getStackName(),
          stackId.getStackVersion(), request.getServiceName());

      if (StringUtils.isNotEmpty(request.getCredentialStoreEnabled())) {
        boolean credentialStoreEnabled = Boolean.parseBoolean(request.getCredentialStoreEnabled());
        if (!serviceInfo.isCredentialStoreSupported() && credentialStoreEnabled) {
          throw new IllegalArgumentException("Invalid arguments, cannot enable credential store " +
              "as it is not supported by the service. Service=" + request.getServiceName());
        }
      }
    }
    // ensure only a single cluster update
    if (serviceNames.size() != 1) {
      throw new IllegalArgumentException("Invalid arguments, updates allowed"
              + "on only one cluster at a time");
    }

    // Validate dups
    if (!duplicates.isEmpty()) {
      String clusterName = requests.iterator().next().getClusterName();
      String msg = "Attempted to create a service which already exists: "
              + ", clusterName=" + clusterName  + " serviceName=" + StringUtils.join(duplicates, ",");

      throw new DuplicateResourceException(msg);
    }

  }
Get any service specific properties for the request.

@param clusterName  cluster name
@param serviceName  service name
@param requestedIds relevant request property ids
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java