|
@@ -63,6 +63,7 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
|
|
|
* Remote Cluster property id constants.
|
|
|
*/
|
|
|
public static final String CLUSTER_NAME_PROPERTY_ID = "ClusterInfo/name";
|
|
|
+ public static final String CLUSTER_ID_PROPERTY_ID = "ClusterInfo/cluster_id";
|
|
|
public static final String CLUSTER_URL_PROPERTY_ID = "ClusterInfo/url";
|
|
|
public static final String USERNAME_PROPERTY_ID = "ClusterInfo/username";
|
|
|
public static final String PASSWORD_PROPERTY_ID = "ClusterInfo/password";
|
|
@@ -87,6 +88,7 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
|
|
|
private static Set<String> propertyIds = new HashSet<String>();
|
|
|
static {
|
|
|
propertyIds.add(CLUSTER_NAME_PROPERTY_ID);
|
|
|
+ propertyIds.add(CLUSTER_ID_PROPERTY_ID);
|
|
|
propertyIds.add(CLUSTER_URL_PROPERTY_ID);
|
|
|
propertyIds.add(USERNAME_PROPERTY_ID);
|
|
|
propertyIds.add(PASSWORD_PROPERTY_ID);
|
|
@@ -167,6 +169,7 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
|
|
|
protected Resource toResource(Set<String> requestedIds, RemoteAmbariClusterEntity cluster) {
|
|
|
Resource resource = new ResourceImpl(Resource.Type.RemoteCluster);
|
|
|
setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, cluster.getName(), requestedIds);
|
|
|
+ setResourceProperty(resource, CLUSTER_ID_PROPERTY_ID, cluster.getId(), requestedIds);
|
|
|
setResourceProperty(resource, CLUSTER_URL_PROPERTY_ID, cluster.getUrl(), requestedIds);
|
|
|
setResourceProperty(resource, USERNAME_PROPERTY_ID, cluster.getUsername(), requestedIds);
|
|
|
ArrayList<String> services = new ArrayList<String>();
|
|
@@ -237,8 +240,14 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
|
|
|
public Void invoke() throws AmbariException {
|
|
|
String name = (String)properties.get(CLUSTER_NAME_PROPERTY_ID);
|
|
|
|
|
|
- if(StringUtils.isEmpty(name)){
|
|
|
- throw new IllegalArgumentException("Cluster Name cannot ne null or Empty");
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
+ throw new IllegalArgumentException("Cluster Name cannot be null or Empty");
|
|
|
+ }
|
|
|
+
|
|
|
+ String id = (String)properties.get(CLUSTER_ID_PROPERTY_ID);
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ throw new IllegalArgumentException("Cluster Id cannot be null or Empty");
|
|
|
}
|
|
|
|
|
|
saveOrUpdateRemoteAmbariClusterEntity(properties,true);
|
|
@@ -261,16 +270,24 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
|
|
|
String username = (String)properties.get(USERNAME_PROPERTY_ID);
|
|
|
String password = (String)properties.get(PASSWORD_PROPERTY_ID);
|
|
|
|
|
|
- if(StringUtils.isEmpty(url) && StringUtils.isEmpty(username)){
|
|
|
+ if (StringUtils.isEmpty(url) && StringUtils.isEmpty(username)) {
|
|
|
throw new IllegalArgumentException("Url or username cannot be null");
|
|
|
}
|
|
|
|
|
|
- RemoteAmbariClusterEntity entity = remoteAmbariClusterDAO.findByName(name);
|
|
|
+ RemoteAmbariClusterEntity entity ;
|
|
|
+
|
|
|
+ if (update) {
|
|
|
+ Long id = Long.valueOf((String) properties.get(CLUSTER_ID_PROPERTY_ID));
|
|
|
+ entity = remoteAmbariClusterDAO.findById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ throw new IllegalArgumentException(String.format("Cannot find cluster with Id : \"%s\"", id));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
|
|
|
- if(update && entity == null){
|
|
|
- throw new IllegalArgumentException(String.format("Cannot find cluster with name : \"%s\"",name));
|
|
|
- }else if(!update && entity != null){
|
|
|
- throw new DuplicateResourceException(String.format("Cluster with name : \"%s\" already exists",name));
|
|
|
+ entity = remoteAmbariClusterDAO.findByName(name);
|
|
|
+ if (entity != null) {
|
|
|
+ throw new DuplicateResourceException(String.format("Cluster with name : \"%s\" already exists", name));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Check Password not null for create
|
|
@@ -288,7 +305,7 @@ public class RemoteClusterResourceProvider extends AbstractAuthorizedResourcePro
|
|
|
entity.setName(name);
|
|
|
entity.setUrl(url);
|
|
|
try {
|
|
|
- if(password != null) {
|
|
|
+ if (password != null) {
|
|
|
entity.setUsername(username);
|
|
|
entity.setPassword(password);
|
|
|
}
|