diff --git a/engine/api/pom.xml b/engine/api/pom.xml index 45153d82469..2abb1ab5643 100644 --- a/engine/api/pom.xml +++ b/engine/api/pom.xml @@ -1,21 +1,13 @@ - + 4.0.0 @@ -42,8 +34,13 @@ org.eclipse.jetty jetty-server - - + + + + org.codehaus.jackson + jackson-jaxrs + 1.9.9 + install diff --git a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceEntity.java b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceEntity.java index 1a331e3a5f9..eccccd6ff22 100755 --- a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceEntity.java +++ b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceEntity.java @@ -18,7 +18,9 @@ */ package org.apache.cloudstack.engine.datacenter.entity.api; +import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.Produces; import org.apache.cloudstack.engine.entity.api.CloudStackEntity; @@ -29,6 +31,7 @@ import com.cloud.utils.fsm.StateObject; * This interface specifies the states and operations all physical * and virtual resources in the data center must implement. */ +@Produces({"application/json", "application/xml"}) public interface DataCenterResourceEntity extends CloudStackEntity, StateObject { /** @@ -87,4 +90,8 @@ public interface DataCenterResourceEntity extends CloudStackEntity, StateObject< @POST boolean reactivate(); + @Override + @GET + State getState(); + } diff --git a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java index 577323c2a4e..92124c2351c 100755 --- a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java +++ b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java @@ -22,14 +22,18 @@ import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.xml.bind.annotation.XmlRootElement; import com.cloud.dc.DataCenter; /** * Describes a zone and operations that can be done in a zone. */ -@Path("zone/{zone-id}") +@XmlRootElement(name="zone") public interface ZoneEntity extends DataCenterResourceEntity, DataCenter { @GET + @Path("/pods") List listPods(); + + List listPodIds(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/PodRestTO.java b/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/PodRestTO.java new file mode 100644 index 00000000000..f831150d31d --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/PodRestTO.java @@ -0,0 +1,35 @@ +/* + * 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.cloudstack.engine.rest.datacenter.entity.api; + +import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity; + +public class PodRestTO { + + public String uuid; + public String name; + + public PodRestTO(PodEntity pod) { + this.uuid = pod.getUuid(); + this.name = pod.getName(); + } + + public PodRestTO() { + } +} diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTO.java b/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTO.java new file mode 100644 index 00000000000..857538e2413 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTO.java @@ -0,0 +1,63 @@ +/* + * 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.cloudstack.engine.rest.datacenter.entity.api; + +import java.net.URI; +import java.util.List; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.UriBuilder; + +import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity; +import org.apache.cloudstack.engine.service.api.ProvisioningService; +import org.springframework.stereotype.Service; + +@Service("zoneService") +@Path("/zone/{zoneid}") +public class ZoneRestTO { + @Inject + protected static ProvisioningService s_provisioningService; + + public String id; + public URI uri; + public String name; + public String[] pods; + + public ZoneRestTO(UriBuilder ub, ZoneEntity zone, URI uri) { + this.id = zone.getUuid(); + this.name = zone.getName(); + this.uri = uri; + List podIds = zone.listPodIds(); + this.pods = new String[podIds.size()]; + this.pods = podIds.toArray(new String[podIds.size()]); + } + + public ZoneRestTO() { + } + + @GET + @Path("/pods") + public String[] listPods(@PathParam("zoneid") String zoneId) { + return this.pods; + } + +} diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTOs.java b/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTOs.java new file mode 100644 index 00000000000..a76490dcbd7 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTOs.java @@ -0,0 +1,23 @@ +/* + * 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.cloudstack.engine.rest.datacenter.entity.api; + +public class ZoneRestTOs { + +} diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.java new file mode 100644 index 00000000000..c3bf9b16b61 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.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.cloudstack.engine.rest.service.api; + +import java.util.Iterator; +import java.util.List; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity; +import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity; +import org.apache.cloudstack.engine.rest.datacenter.entity.api.PodRestTO; +import org.apache.cloudstack.engine.rest.datacenter.entity.api.ZoneRestTO; +import org.apache.cloudstack.engine.service.api.ProvisioningService; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + + +@Service("provisioningService") +@Path("/provisioning") +@Produces({"application/xml", "application/json"}) +@Component +public class ProvisioningRestService { + @Inject + ProvisioningService _provisioningService; + + @GET + @Path("/{zoneid}") + public ZoneRestTO getZone(@Context UriInfo ui, @PathParam("zoneid") String id) { + UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone"); + ZoneEntity entity = _provisioningService.getZone(id); + return new ZoneRestTO(ub, entity, ub.build(entity.getUuid())); + } + + @GET + @Path("/zones") + public ZoneRestTO[] listZones(@Context UriInfo ui) { + List zones = _provisioningService.listZones(); + ZoneRestTO[] tos = new ZoneRestTO[zones.size()]; + UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone"); + Iterator it = zones.iterator(); + for (int i = 0; i < tos.length; i++) { + ZoneEntity entity = it.next(); + tos[i] = new ZoneRestTO(ub, entity, ub.build(entity.getUuid())); + } + return tos; + } + + @GET + @Path("/zone/{zoneid}/pods") + public PodRestTO[] listPods(@PathParam("zoneid") String zoneId) { + List pods = _provisioningService.listPods(); + PodRestTO[] tos = new PodRestTO[pods.size()]; + Iterator it = pods.iterator(); + for (int i = 0; i < tos.length; i++) { + PodEntity pod = it.next(); + tos[i] = new PodRestTO(pod); + } + return tos; + } +} diff --git a/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java b/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java index a8cd5d2f359..c2696bf67b4 100755 --- a/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java +++ b/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java @@ -21,18 +21,11 @@ package org.apache.cloudstack.engine.service.api; import java.util.List; import java.util.Map; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity; import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity; import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity; import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity; -import com.cloud.dc.Pod; import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.storage.StoragePool; @@ -42,56 +35,37 @@ import com.cloud.storage.StoragePool; * ProvisioningService registers and deregisters physical and virtual * resources that the management server can use. */ -@Path("/provision") -@Produces({"application/json", "application/xml"}) public interface ProvisioningService { - @POST StorageEntity registerStorage(String name, List tags, Map details); - @POST ZoneEntity registerZone(String name, List tags, Map details); - @POST PodEntity registerPod(String name, List tags, Map details); - @POST ClusterEntity registerCluster(String name, List tags, Map details); - @POST String registerHost(String name, List tags, Map details); - @DELETE void deregisterStorage(String uuid); - @DELETE void deregisterZone(); - @DELETE void deregisterPod(); - @DELETE void deregisterCluster(); - @DELETE void deregisterHost(); void changeState(String type, String entity, Status state); - @GET - @Path("/hosts") List listHosts(); - @GET - @Path("/pods") - List listPods(); + List listPods(); - @GET - @Path("/zones") List listZones(); - @GET - @Path("/storages") List listStorage(); + ZoneEntity getZone(String id); } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntityImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntityImpl.java new file mode 100755 index 00000000000..978bbcbd200 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntityImpl.java @@ -0,0 +1,197 @@ +/* + * 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.cloudstack.engine.datacenter.entity.api; + +import java.lang.reflect.Method; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import com.cloud.org.Cluster; + +public class PodEntityImpl implements PodEntity { + String _uuid; + String _name; + + public PodEntityImpl(String uuid, String name) { + _uuid = uuid; + _name = name; + } + + @Override + public boolean enable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean disable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean deactivate() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean reactivate() { + // TODO Auto-generated method stub + return false; + } + + @Override + public State getState() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getUuid() { + return _uuid; + } + + @Override + public long getId() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getCurrentState() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getDesiredState() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Date getCreatedTime() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Date getLastUpdatedTime() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getOwner() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map getDetails(String source) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getDetailSources() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void addDetail(String source, String name, String value) { + // TODO Auto-generated method stub + + } + + @Override + public void delDetail(String source, String name, String value) { + // TODO Auto-generated method stub + + } + + @Override + public void updateDetail(String source, String name, String value) { + // TODO Auto-generated method stub + + } + + @Override + public List getApplicableActions() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getCidrAddress() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getCidrSize() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getGateway() { + // TODO Auto-generated method stub + return null; + } + + @Override + public long getDataCenterId() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getName() { + return _name; + } + + @Override + public AllocationState getAllocationState() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean getExternalDhcp() { + // TODO Auto-generated method stub + return false; + } + + @Override + public List listClusters() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java index cd62155b7da..71c1f256bd2 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java @@ -19,50 +19,52 @@ package org.apache.cloudstack.engine.datacenter.entity.api; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -@Path("/zone/{id}") public class ZoneEntityImpl implements ZoneEntity { + String _id; + String _name; + + // This is a test constructor + public ZoneEntityImpl(String id, String name) { + _id = id; + _name = name; + } + + public ZoneEntityImpl() { + } @Override - @POST public boolean enable() { // TODO Auto-generated method stub return false; } @Override - @POST public boolean disable() { // TODO Auto-generated method stub return false; } @Override - @POST public boolean deactivate() { // TODO Auto-generated method stub return false; } @Override - @POST public boolean reactivate() { // TODO Auto-generated method stub return false; } @Override - @GET public String getUuid() { - // TODO Auto-generated method stub - return null; + return _id; } @Override @@ -72,35 +74,30 @@ public class ZoneEntityImpl implements ZoneEntity { } @Override - @GET public String getCurrentState() { // TODO Auto-generated method stub return "state"; } @Override - @GET public String getDesiredState() { // TODO Auto-generated method stub return "desired_state"; } @Override - @GET public Date getCreatedTime() { // TODO Auto-generated method stub return new Date(); } @Override - @GET public Date getLastUpdatedTime() { // TODO Auto-generated method stub return new Date(); } @Override - @GET public String getOwner() { // TODO Auto-generated method stub return "owner"; @@ -168,8 +165,7 @@ public class ZoneEntityImpl implements ZoneEntity { @Override public String getName() { - // TODO Auto-generated method stub - return null; + return _name; } @Override @@ -291,4 +287,12 @@ public class ZoneEntityImpl implements ZoneEntity { // TODO Auto-generated method stub return null; } + + @Override + public List listPodIds() { + List podIds = new ArrayList(); + podIds.add("pod-uuid-1"); + podIds.add("pod-uuid-2"); + return podIds; + } } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java index d3c0e112e88..8b62d48fe32 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java @@ -22,23 +22,19 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity; import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity; +import org.apache.cloudstack.engine.datacenter.entity.api.PodEntityImpl; import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity; import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity; -import org.springframework.stereotype.Service; +import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntityImpl; +import org.springframework.stereotype.Component; -import com.cloud.dc.Pod; import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.storage.StoragePool; -@Service("provisioningService") -@Path("/provisioning") +@Component public class ProvisioningServiceImpl implements ProvisioningService { @Override @@ -114,18 +110,18 @@ public class ProvisioningServiceImpl implements ProvisioningService { } @Override - public List listPods() { - // TODO Auto-generated method stub + public List listPods() { + List pods = new ArrayList(); + pods.add(new PodEntityImpl("pod-uuid-1", "pod1")); + pods.add(new PodEntityImpl("pod-uuid-2", "pod2")); return null; } @Override - @GET - @Path("/zones") - @Produces("text/plain") public List listZones() { List zones = new ArrayList(); - // TODO Auto-generated method stub + zones.add(new ZoneEntityImpl("zone-uuid-1", "name1")); + zones.add(new ZoneEntityImpl("zone-uuid-2", "name2")); return zones; } @@ -135,4 +131,10 @@ public class ProvisioningServiceImpl implements ProvisioningService { return null; } + @Override + public ZoneEntity getZone(String uuid) { + ZoneEntityImpl impl = new ZoneEntityImpl(uuid, "name"); + return impl; + } + } diff --git a/engine/service/src/main/webapp/WEB-INF/beans.xml b/engine/service/src/main/webapp/WEB-INF/beans.xml index 6f6cf3be0af..55aaa5778df 100755 --- a/engine/service/src/main/webapp/WEB-INF/beans.xml +++ b/engine/service/src/main/webapp/WEB-INF/beans.xml @@ -10,11 +10,15 @@ - + - + + + + + diff --git a/engine/service/src/main/webapp/WEB-INF/web.xml b/engine/service/src/main/webapp/WEB-INF/web.xml index 7a3f1520bc3..71c1ef38329 100644 --- a/engine/service/src/main/webapp/WEB-INF/web.xml +++ b/engine/service/src/main/webapp/WEB-INF/web.xml @@ -2,7 +2,11 @@ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > - + contextConfigLocation WEB-INF/beans.xml