Browse Source

AMBARI-799. Prototype for management spi part 3. (hitesh)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1393803 13f79535-47bb-0310-9956-ffa450edef68
Hitesh Shah 12 years ago
parent
commit
3b73adaa12

+ 2 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-799. Prototype for management spi part 3. (hitesh)
+
   AMBARI-797. Prototype for management spi interface continued. (hitesh)
 
   AMBARI-795. Fix failing tests for AgentResource and BootStrap. (mahadev)

+ 18 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.controller;
 
 import java.util.HashMap;

+ 62 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Config.java

@@ -1,5 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state;
 
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Represents a single instance of a 'Config Type'
+ */
 public interface Config {
 
+  /**
+   * @return Config Type
+   */
+  public String getType();
+
+  /**
+   * @return Version Tag this config instance is mapped to
+   */
+  public String getVersionTag();
+
+  /**
+   * @return Properties that define this config instance
+   */
+  public Map<String, String> getProperties();
+
+  /**
+   * Change the version tag
+   * @param versionTag
+   */
+  public void setVersionTag(String versionTag);
+
+  /**
+   * Replace properties with new provided set
+   * @param properties Property Map to replace existing one
+   */
+  public void setProperties(Map<String, String> properties);
+
+  /**
+   * Update provided properties' values.
+   * @param properties Property Map with updated values
+   */
+  public void updateProperties(Map<String, String> properties);
+
+  /**
+   * Delete certain properties
+   * @param properties Property keys to be deleted
+   */
+  public void deleteProperties(List<String> properties);
 }

+ 84 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java

@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.state;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ConfigImpl implements Config {
+  
+  private final String type;
+  
+  private String versionTag;
+  
+  private Map<String, String> properties;
+
+  public ConfigImpl(String type, String versionTag,
+      Map<String, String> properties) {
+    this.type = type;
+    this.versionTag = versionTag;
+    this.properties = properties;
+  }
+  
+  public ConfigImpl(String type, String versionTag) {
+    this(type, versionTag, new HashMap<String, String>());
+  }
+  
+  @Override
+  public String getType() {
+    return type;
+  }
+
+  @Override
+  public synchronized String getVersionTag() {
+    return versionTag;
+  }
+
+  @Override
+  public synchronized Map<String, String> getProperties() {
+    return Collections.unmodifiableMap(properties);
+  }
+
+  @Override
+  public synchronized void setVersionTag(String versionTag) {
+    this.versionTag = versionTag;
+  }
+
+  @Override
+  public synchronized void setProperties(Map<String, String> properties) {
+    this.properties = properties;
+  }
+
+  @Override
+  public synchronized void updateProperties(Map<String, String> properties) {
+    this.properties.putAll(properties);
+  }
+
+  @Override
+  public synchronized void deleteProperties(List<String> properties) {
+    for (String key : properties) {
+      this.properties.remove(key);
+    }
+  }
+  
+  
+
+}

+ 27 - 6
ambari-server/src/main/java/org/apache/ambari/server/state/Service.java

@@ -1,8 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state;
 
 import java.util.Map;
 
-
 public interface Service {
 
   public String getName();
@@ -11,15 +28,19 @@ public interface Service {
   
   public long getCurrentHostComponentMappingVersion();
 
+  public void setCurrentHostComponentMappingVersion(long version);
+
   public Map<String, ServiceComponent> getServiceComponents();
-    
-  public State getState();
+
+  public void addServiceComponents(Map<String, ServiceComponent> components);
+
+  public DeployState getState();
   
-  public void setState(State state);
+  public void setState(DeployState state);
 
-  public Config getConfig();
+  public Map<String, Config> getConfigs();
 
-  public void setConfig(Config config);
+  public void updateConfigs(Map<String, Config> configs);
   
   public StackVersion getStackVersion();
   

+ 25 - 5
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java

@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state;
 
 import java.util.Map;
@@ -12,18 +30,20 @@ public interface ServiceComponent {
 
   public long getClusterId();
   
-  public State getState();
+  public DeployState getState();
   
-  public void setState(State state);
+  public void setState(DeployState state);
 
-  public Config getConfig();
+  public Map<String, Config> getConfigs();
 
-  public void setConfig(Config config);
+  public void updateConfigs(Map<String, Config> configs);
   
   public StackVersion getStackVersion();
   
   public void setStackVersion(StackVersion stackVersion);
-
+  
   public Map<String, ServiceComponentHost> getServiceComponentHosts();
   
+  public void addServiceComponentHosts(Map<String, ServiceComponentHost>
+      hostComponents);
 }

+ 117 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java

@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.state;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHost;
+
+public class ServiceComponentImpl implements ServiceComponent {
+
+  private final Service service;
+  
+  private final String componentName;
+  
+  private DeployState state;
+  
+  private Map<String, Config> configs;
+
+  private Map<String, ServiceComponentHost> hostComponents;
+  
+  private StackVersion stackVersion;
+
+  private void init() {
+    // TODO
+    // initialize from DB 
+  }
+  
+  public ServiceComponentImpl(Service service,
+      String componentName, DeployState state, Map<String, Config> configs) {
+    this.service = service;
+    this.componentName = componentName;
+    this.state = state;
+    if (configs != null) {
+      this.configs = configs;
+    } else {
+      this.configs = new HashMap<String, Config>();
+    }
+    this.hostComponents = new HashMap<String, ServiceComponentHost>();
+    init();
+  }
+  
+  @Override
+  public synchronized String getName() {
+    return componentName;
+  }
+
+  @Override
+  public synchronized String getServiceName() {
+    return service.getName();
+  }
+
+  @Override
+  public synchronized long getClusterId() {
+    return this.service.getClusterId();
+  }
+
+  @Override
+  public synchronized DeployState getState() {
+    return state;
+  }
+
+  @Override
+  public synchronized void setState(DeployState state) {
+    this.state = state;
+  }
+
+  @Override
+  public synchronized Map<String, Config> getConfigs() {
+    return Collections.unmodifiableMap(configs);
+  }
+
+  @Override
+  public synchronized void updateConfigs(Map<String, Config> configs) {
+    this.configs = configs;
+  }
+
+  @Override
+  public synchronized StackVersion getStackVersion() {
+    return stackVersion;
+  }
+
+  @Override
+  public synchronized void setStackVersion(StackVersion stackVersion) {
+    this.stackVersion = stackVersion;
+  }
+
+  @Override
+  public synchronized Map<String, ServiceComponentHost>
+      getServiceComponentHosts() {
+    return Collections.unmodifiableMap(hostComponents);
+  }
+
+  @Override
+  public synchronized void addServiceComponentHosts(
+      Map<String, ServiceComponentHost> hostComponents) {
+    this.hostComponents.putAll(hostComponents);
+  }
+
+}

+ 44 - 20
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java

@@ -1,5 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.apache.ambari.server.state;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -12,6 +31,7 @@ public class ServiceImpl implements Service {
   private DeployState state;
   private Map<String, Config> configs;
   private Map<String, ServiceComponent> components;
+  private StackVersion stackVersion;
   
   private void init() {
     // TODO
@@ -52,51 +72,55 @@ public class ServiceImpl implements Service {
   }
 
   @Override
-  public long getCurrentHostComponentMappingVersion() {
+  public synchronized long getCurrentHostComponentMappingVersion() {
     // TODO Auto-generated method stub
     return 0;
   }
 
   @Override
-  public Map<String, ServiceComponent> getServiceComponents() {
-    // TODO Auto-generated method stub
-    return null;
+  public synchronized Map<String, ServiceComponent> getServiceComponents() {
+    return Collections.unmodifiableMap(components);
   }
 
   @Override
-  public State getState() {
-    // TODO Auto-generated method stub
-    return null;
+  public synchronized DeployState getState() {
+    return state;
   }
 
   @Override
-  public void setState(State state) {
-    // TODO Auto-generated method stub
-
+  public synchronized void setState(DeployState state) {
+    this.state = state;
   }
 
   @Override
-  public Config getConfig() {
-    // TODO Auto-generated method stub
-    return null;
+  public synchronized StackVersion getStackVersion() {
+    return stackVersion;
   }
 
   @Override
-  public void setConfig(Config config) {
-    // TODO Auto-generated method stub
+  public synchronized void setStackVersion(StackVersion stackVersion) {
+    this.stackVersion = stackVersion;
+  }
 
+  @Override
+  public synchronized Map<String, Config> getConfigs() {
+    return Collections.unmodifiableMap(configs);
   }
 
   @Override
-  public StackVersion getStackVersion() {
-    // TODO Auto-generated method stub
-    return null;
+  public synchronized void updateConfigs(Map<String, Config> configs) {
+    this.configs.putAll(configs);
   }
 
   @Override
-  public void setStackVersion(StackVersion stackVersion) {
-    // TODO Auto-generated method stub
+  public synchronized void setCurrentHostComponentMappingVersion(long version) {
+    // TODO Auto-generated method stub    
+  }
 
+  @Override
+  public synchronized void addServiceComponents(
+      Map<String, ServiceComponent> components) {
+    this.components.putAll(components);
   }
 
 }