Browse Source

AMBARI-733. Add Jersey Resource for BootStrapping and JAXB elements for API entities. (mahadev)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1384660 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 12 years ago
parent
commit
5edd07b75d

+ 3 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,9 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-733. Add Jersey Resource for BootStrapping and JAXB elements for API
+  entities. (mahadev)
+
   AMBARI-730. Add unit tests for jersey apis on the server. (mahadev)
 
   AMBARI-725. Add commandstatus/result/error objects into the rest API between

+ 66 - 0
ambari-server/src/main/java/org/apache/ambari/server/api/rest/BootStrapResource.java

@@ -0,0 +1,66 @@
+/**
+ * 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.api.rest;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.ambari.server.bootstrap.BootStrapPostStatus;
+import org.apache.ambari.server.bootstrap.BootStrapStatus;
+import org.apache.ambari.server.bootstrap.SshHostInfo;
+
+@Path("/bootstrap")
+public class BootStrapResource {
+  
+  /**
+   * Run bootstrap on a list of hosts.
+   * @response.representation.200.doc 
+   * 
+   * @response.representation.200.mediaType application/json
+   * @response.representation.406.doc Error in format
+   * @response.representation.408.doc Request Timed out
+   * @throws Exception
+   */
+  @POST
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) 
+  public BootStrapPostStatus bootStrap(SshHostInfo sshInfo) {
+    
+    return new BootStrapPostStatus();
+  }
+  
+  /**
+   * Current BootStrap Information thats running.
+   * @response.representation.200.doc 
+   * 
+   * @response.representation.200.mediaType application/json
+   * @response.representation.406.doc Error in format
+   * @response.representation.408.doc Request Timed out
+   * @throws Exception
+   */
+  @GET
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) 
+  public BootStrapStatus getBootStrapStatus() {
+    return new BootStrapStatus();
+  }
+}

+ 64 - 0
ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSHostStatus.java

@@ -0,0 +1,64 @@
+/**
+ * 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.bootstrap;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ *  BootStrap Status for a host.
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
+public class BSHostStatus {
+  @XmlElement
+  private String status;
+  @XmlElement 
+  private String hostName;
+  @XmlElement
+  private String log;
+  
+  public void setStatus(String status) {
+    this.status = status;
+  }
+  
+  public String getStatus() {
+    return this.status;
+  }
+  
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+  
+  public String getHostName() {
+    return this.hostName;
+  }
+  
+  public String getLog() {
+    return this.log;
+  }
+  
+  public void setLog(String log) {
+    this.log = log;
+  }
+}

+ 73 - 0
ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BootStrapPostStatus.java

@@ -0,0 +1,73 @@
+/**
+ * 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.bootstrap;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * Class captures immediate response to a bootstrap api call.
+ * If the api call is ok, the return should return that its ok.
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
+public class BootStrapPostStatus {
+  @XmlType(name="status")
+  @XmlEnum
+  public enum BSPostStat {
+    OK,
+    ERROR
+  }
+  
+  @XmlElement 
+  private BSPostStat postStatus;
+  @XmlElement 
+  private String log;
+  @XmlElement 
+  private long requestId;
+  
+  public long getRequestId() {
+    return this.requestId;
+  }
+  
+  public void setRequestId(long requestId) {
+    this.requestId = requestId;
+  }
+  
+  public BSPostStat getStatus() {
+    return this.postStatus;
+  }
+  
+  public void setStatus(BSPostStat status) {
+    this.postStatus  = status;
+  }
+  
+  public String getLog() {
+    return this.log;
+  }
+  
+  public void setLog(String log) {
+    this.log = log;
+  }
+}

+ 68 - 0
ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BootStrapStatus.java

@@ -0,0 +1,68 @@
+/**
+ * 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.bootstrap;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * Status of a bootstrap operation. Operation is successful or error 
+ * and explains all the info regarding the operation on each host.
+ *
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
+public class BootStrapStatus {
+  @XmlType(name="status")
+  @XmlEnum
+  public enum BSStat {
+    OK,
+    ERROR
+  }
+  
+  @XmlElement 
+  private BSStat status;
+  
+  @XmlElement
+  private List<BSHostStatus> hostsStatus;
+  
+  public void setStatus(BSStat status) {
+    this.status = status;
+  }
+  
+  public BSStat getStatus() {
+    return this.status;
+  }
+  
+  public void setHostsStatus(List<BSHostStatus> hostsStatus) {
+    this.hostsStatus = hostsStatus;
+  }
+  
+  public List<BSHostStatus> getHostsStatus() {
+    return this.hostsStatus;
+  }
+}

+ 60 - 0
ambari-server/src/main/java/org/apache/ambari/server/bootstrap/SshHostInfo.java

@@ -0,0 +1,60 @@
+/**
+ * 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.bootstrap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * Information that the API needs to provide to run bootstrap on hosts.
+ * 
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {})
+public class SshHostInfo {
+  
+  @XmlElement
+  private String sshKey;
+  
+  @XmlElement 
+  private List<String>  hosts = new ArrayList<String>();
+  
+  public String getSshKey() {
+    return sshKey;
+  }
+  
+  public void setSshKey(String sshKey) {
+    this.sshKey = sshKey;
+  }
+  
+  public void setHosts(List<String> hosts) {
+    this.hosts = hosts;
+  }
+  
+  public List<String> getHosts() {
+    return this.hosts;
+  }
+}

+ 0 - 2
ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java

@@ -18,9 +18,7 @@
 
 package org.apache.ambari.server.agent;
 
-import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import javax.ws.rs.core.MediaType;