public void saveOrUpdate(RemoteAmbariClusterEntity entity, boolean update) throws IOException, AmbariHttpException {

    RemoteAmbariCluster cluster = new RemoteAmbariCluster(entity, configuration);
    Set<String> services = cluster.getServices();

    if (!cluster.isAmbariOrClusterAdmin()) {
      throw new AmbariException("User must be Ambari or Cluster Adminstrator.");
    }

    Collection<RemoteAmbariClusterServiceEntity> serviceEntities = new ArrayList<>();

    for (String service : services) {
      RemoteAmbariClusterServiceEntity serviceEntity = new RemoteAmbariClusterServiceEntity();
      serviceEntity.setServiceName(service);
      serviceEntity.setCluster(entity);
      serviceEntities.add(serviceEntity);
    }

    entity.setServices(serviceEntities);

    if (update) {
      update(entity);
    } else {
      remoteAmbariClusterDAO.save(entity);
    }
  }
Save Remote Cluster Entity after setting services.

@param entity
@param update
@throws IOException
@throws AmbariHttpException
ambari-server/src/main/java/org/apache/ambari/server/view/RemoteAmbariClusterRegistry.java