From e936c32a04c32ee8b3496ef794e411a0a2e8e902 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Fri, 28 Dec 2012 16:24:54 -0800 Subject: [PATCH] Fixed problems with inject checkin --- .../datacenter/entity/api/ZoneEntity.java | 7 + .../rest/datacenter/entity/api/PodRestTO.java | 35 ---- .../datacenter/entity/api/ZoneRestTO.java | 78 --------- .../datacenter/entity/api/ZoneRestTOs.java | 23 --- .../rest/service/api/ClusterRestService.java | 87 +++++++++ .../rest/service/api/NetworkRestService.java | 60 +++++++ .../rest/service/api/PodRestService.java | 80 +++++++++ .../service/api/ProvisioningRestService.java | 82 --------- .../api/VirtualMachineRestService.java | 56 ++++++ .../rest/service/api/VolumeRestService.java | 76 ++++++++ .../rest/service/api/ZoneRestService.java | 88 ++++++++++ .../datacenter/entity/api/ZoneEntityImpl.java | 3 + .../service/src/main/webapp/WEB-INF/beans.xml | 11 +- .../com/cloud/dc/dao/DataCenterDaoImpl.java | 165 +++++++++--------- .../cloud/network/rules/FirewallRuleVO.java | 87 +++++---- 15 files changed, 590 insertions(+), 348 deletions(-) delete mode 100644 engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/PodRestTO.java delete mode 100644 engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTO.java delete mode 100644 engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTOs.java create mode 100755 engine/api/src/org/apache/cloudstack/engine/rest/service/api/ClusterRestService.java create mode 100755 engine/api/src/org/apache/cloudstack/engine/rest/service/api/NetworkRestService.java create mode 100755 engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java delete mode 100644 engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.java create mode 100755 engine/api/src/org/apache/cloudstack/engine/rest/service/api/VirtualMachineRestService.java create mode 100755 engine/api/src/org/apache/cloudstack/engine/rest/service/api/VolumeRestService.java create mode 100755 engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java 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 2b683e2c9a7..fb033b0e7d1 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,6 +22,7 @@ import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.Produces; import javax.xml.bind.annotation.XmlRootElement; import org.apache.cloudstack.engine.service.api.ProvisioningService; @@ -32,6 +33,8 @@ import com.cloud.dc.DataCenter; /** * Describes a zone and operations that can be done in a zone. */ +@Path("/zone/{zoneid}") +@Produces({"application/json"}) @XmlRootElement(name="zone") public interface ZoneEntity extends DataCenterResourceEntity, DataCenter { @GET @@ -40,4 +43,8 @@ public interface ZoneEntity extends DataCenterResourceEntity, DataCenter { @Url(clazz=ProvisioningService.class, method="getPod", name="id", type=List.class) List listPodIds(); + + @Override + @Path("/enable") + boolean enable(); } 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 deleted file mode 100644 index f831150d31d..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/PodRestTO.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 deleted file mode 100644 index f351dd053d0..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTO.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.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.core.Context; -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.core.UriInfo; - -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 URI[] pods; - - public ZoneRestTO(UriInfo ui, ZoneEntity zone, URI uri) { - this.id = zone.getUuid(); - this.name = zone.getName(); - this.uri = uri; - List podIds = zone.listPodIds(); - this.pods = new URI[podIds.size()]; - UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getPod"); - Iterator it = podIds.iterator(); - for (int i = 0; i < pods.length; i++) { - String pod = it.next(); - pods[i] = ub.build(pod); - } - } - - public ZoneRestTO() { - } - - @GET - @Path("/pods") - public URI[] listPods(@PathParam("zoneid") String zoneId) { - return this.pods; - } - - @GET - @Path("/pod/{podid}") - public PodRestTO getPod(@Context UriInfo ui, @PathParam("podid") String podId) { - return null; - } - -} 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 deleted file mode 100644 index a76490dcbd7..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/rest/datacenter/entity/api/ZoneRestTOs.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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/ClusterRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ClusterRestService.java new file mode 100755 index 00000000000..7c45c45e7f3 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ClusterRestService.java @@ -0,0 +1,87 @@ +/* + * 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.List; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity; +import org.apache.cloudstack.engine.service.api.ProvisioningService; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Component +@Service("ClusterRestService") +@Produces("application/json") +public class ClusterRestService { + @Inject + ProvisioningService _provisioningService; + + @GET @Path("/clusters") + public List listAll() { + return null; + } + + + @GET @Path("/cluster/{clusterid}") + public ClusterEntity get(@PathParam("clusterid") String clusterId) { + return null; + } + + @POST @Path("/cluster/{clusterid}/enable") + public String enable(@PathParam("clusterid") String clusterId) { + return null; + } + + @POST @Path("/cluster/{clusterid}/disable") + public String disable(@PathParam("clusterid") String clusterId) { + return null; + } + + @POST @Path("/cluster/{clusterid}/deactivate") + public String deactivate(@PathParam("clusterid") String clusterId) { + return null; + } + + @POST @Path("/cluster/{clusterid}/reactivate") + public String reactivate(@PathParam("clusterid") String clusterId) { + return null; + } + + @PUT @Path("/cluster/create") + public ClusterEntity create( + @QueryParam("xid") String xid, + @QueryParam("display-name") String displayName) { + return null; + } + + @PUT @Path("/cluster/{clusterid}/update") + public ClusterEntity update( + @QueryParam("display-name") String displayName) { + return null; + } +} diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/NetworkRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/NetworkRestService.java new file mode 100755 index 00000000000..281a7714906 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/NetworkRestService.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.cloudstack.engine.rest.service.api; + +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Service("NetworkRestService") +@Component +@Produces("application/json") +public class NetworkRestService { + @PUT @Path("/network/create") + public NetworkEntity create( + @QueryParam("xid") String xid, + @QueryParam("display-name") String displayName) { + return null; + } + + @GET @Path("/network/{network-id}") + public NetworkEntity get(@PathParam("network-id") String networkId) { + return null; + } + + @GET @Path("/networks") + public List listAll() { + return null; + } + + @POST @Path("/network/{network-id}/") + public String deploy(@PathParam("network-id") String networkId) { + return null; + } +} diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java new file mode 100755 index 00000000000..d235f97fa2a --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java @@ -0,0 +1,80 @@ +/* + * 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 javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity; +import org.apache.cloudstack.engine.service.api.ProvisioningService; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Component +@Service("PodService") +@Produces({"application/json"}) +public class PodRestService { + @Inject + ProvisioningService _provisioningService; + + @GET @Path("/pod/{pod-id}") + public PodEntity getPod(@PathParam("pod-id") String podId) { + return null; + } + + @POST @Path("/pod/{pod-id}/enable") + public String enable(@PathParam("pod-id") String podId) { + return null; + } + + @POST @Path("/pod/{pod-id}/disable") + public String disable(@PathParam("pod-id") String podId) { + return null; + } + + @POST @Path("/pod/{pod-id}/deactivate") + public String deactivate(@PathParam("pod-id") String podId) { + return null; + } + + @POST @Path("/pod/{pod-id}/reactivate") + public String reactivate(@PathParam("pod-id") String podId) { + return null; + } + + @PUT @Path("/pod/create") + public PodEntity create( + @QueryParam("xid") String xid, + @QueryParam("display-name") String displayName) { + return null; + } + + @PUT @Path("/pod/{pod-id}") + public PodEntity update( + @PathParam("pod-id") String podId, + @QueryParam("display-name") String displayName) { + return null; + } +} 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 deleted file mode 100644 index fe2aa5b1730..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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; - - -@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(ui, 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(ui, 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/rest/service/api/VirtualMachineRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/VirtualMachineRestService.java new file mode 100755 index 00000000000..2124a81261f --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/VirtualMachineRestService.java @@ -0,0 +1,56 @@ +/* + * 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.List; + +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Component +@Service("VirtualMachineRestService") +@Produces("application/xml") +public class VirtualMachineRestService { + + @GET @Path("/vm/{vmid}") + public VirtualMachineEntity get(@PathParam("vmid") String vmId) { + return null; + } + + @PUT @Path("/vm/create") + public VirtualMachineEntity create( + @QueryParam("xid") String xid, + @QueryParam("hostname") String hostname, + @QueryParam("display-name") String displayName) { + return null; + } + + @GET @Path("/vms") + public List listAll() { + return null; + } +} diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/VolumeRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/VolumeRestService.java new file mode 100755 index 00000000000..3e5174b9d90 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/VolumeRestService.java @@ -0,0 +1,76 @@ +/* + * 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.List; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Component +@Service("VolumeRestService") +@Produces("application/json") +public class VolumeRestService { + + @PUT @Path("/vol/create") + public VolumeEntity create( + @QueryParam("xid") String xid, + @QueryParam("display-name") String displayName) { + return null; + } + + @POST @Path("/vol/{volid}/deploy") + public String deploy(@PathParam("volid") String volumeId) { + return null; + } + + @GET @Path("/vols") + public List listAll() { + return null; + } + + @POST @Path("/vol/{volid}/attach-to") + public String attachTo( + @PathParam("volid") String volumeId, + @QueryParam("vmid") String vmId, + @QueryParam("device-order") short device) { + return null; + } + + @DELETE @Path("/vol/{volid}") + public String delete(@PathParam("volid") String volumeId) { + return null; + } + + @POST @Path("/vol/{volid}/detach") + public String detach(@QueryParam("volid") String volumeId) { + return null; + } + +} diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java new file mode 100755 index 00000000000..318b153714d --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java @@ -0,0 +1,88 @@ +/* + * 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.List; + +import javax.inject.Inject; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; + +import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity; +import org.apache.cloudstack.engine.service.api.ProvisioningService; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Component +@Service("zoneService") +@Produces({"application/json"}) +public class ZoneRestService { + @Inject + ProvisioningService _provisioningService; + + @GET @Path("/zones") + public List listAll() { + return _provisioningService.listZones(); + } + + @GET @Path("/zone/{zone-id}") + public ZoneEntity get(@PathParam("zone-id") String zoneId) { + return _provisioningService.getZone(zoneId); + } + + @POST @Path("/zone/{zone-id}/enable") + public String enable(String zoneId) { + return null; + } + + @POST @Path("/zone/{zone-id}/disable") + public String disable(@PathParam("zone-id") String zoneId) { + ZoneEntity zoneEntity = _provisioningService.getZone(zoneId); + zoneEntity.disable(); + return null; + } + + @POST @Path("/zone/{zone-id}/deactivate") + public String deactivate(@PathParam("zone-id") String zoneId) { + return null; + } + + @POST @Path("/zone/{zone-id}/activate") + public String reactivate(@PathParam("zone-id") String zoneId) { + return null; + } + + + @PUT @Path("/zone/create") + public ZoneEntity createZone(@QueryParam("xid") String xid, + @QueryParam("display-name") String displayName) { + return null; + } + + @DELETE @Path("/zone/{zone-id}") + public String deleteZone(@QueryParam("zone-id") String xid) { + 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 71c1f256bd2..cd3898c8828 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 @@ -24,7 +24,10 @@ import java.util.Date; import java.util.List; import java.util.Map; +import org.springframework.stereotype.Service; + +@Service("zoneService") public class ZoneEntityImpl implements ZoneEntity { String _id; String _name; diff --git a/engine/service/src/main/webapp/WEB-INF/beans.xml b/engine/service/src/main/webapp/WEB-INF/beans.xml index c7151ee700f..4e3a2555fa0 100755 --- a/engine/service/src/main/webapp/WEB-INF/beans.xml +++ b/engine/service/src/main/webapp/WEB-INF/beans.xml @@ -10,12 +10,15 @@ - + - + - - + + + + + diff --git a/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java b/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java index 5ffc2b4f710..730029de3fc 100755 --- a/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java +++ b/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java @@ -36,7 +36,6 @@ import com.cloud.dc.PodVlanVO; import com.cloud.org.Grouping; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; -import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; @@ -63,43 +62,44 @@ public class DataCenterDaoImpl extends GenericDaoBase implem protected SearchBuilder ChildZonesSearch; protected SearchBuilder DisabledZonesSearch; protected SearchBuilder TokenSearch; - - @Inject protected final DataCenterIpAddressDaoImpl _ipAllocDao; - @Inject protected final DataCenterLinkLocalIpAddressDaoImpl _LinkLocalIpAllocDao; - @Inject protected final DataCenterVnetDaoImpl _vnetAllocDao; - @Inject protected final PodVlanDaoImpl _podVlanAllocDao; + + @Inject protected DataCenterIpAddressDaoImpl _ipAllocDao = null; + @Inject protected DataCenterLinkLocalIpAddressDaoImpl _LinkLocalIpAllocDao = null; + @Inject protected DataCenterVnetDaoImpl _vnetAllocDao = null; + @Inject protected PodVlanDaoImpl _podVlanAllocDao = null; + @Inject protected DcDetailsDaoImpl _detailsDao = null; + protected long _prefix; protected Random _rand = new Random(System.currentTimeMillis()); protected TableGenerator _tgMacAddress; - - @Inject protected final DcDetailsDaoImpl _detailsDao; + @Override public DataCenterVO findByName(String name) { - SearchCriteria sc = NameSearch.create(); - sc.setParameters("name", name); + SearchCriteria sc = NameSearch.create(); + sc.setParameters("name", name); return findOneBy(sc); } - + @Override public DataCenterVO findByToken(String zoneToken){ - SearchCriteria sc = TokenSearch.create(); - sc.setParameters("zoneToken", zoneToken); + SearchCriteria sc = TokenSearch.create(); + sc.setParameters("zoneToken", zoneToken); return findOneBy(sc); } - + @Override public List findZonesByDomainId(Long domainId){ - SearchCriteria sc = ListZonesByDomainIdSearch.create(); - sc.setParameters("domainId", domainId); + SearchCriteria sc = ListZonesByDomainIdSearch.create(); + sc.setParameters("domainId", domainId); return listBy(sc); } - + @Override public List findZonesByDomainId(Long domainId, String keyword){ - SearchCriteria sc = ListZonesByDomainIdSearch.create(); - sc.setParameters("domainId", domainId); - if (keyword != null) { + SearchCriteria sc = ListZonesByDomainIdSearch.create(); + sc.setParameters("domainId", domainId); + if (keyword != null) { SearchCriteria ssc = createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -107,12 +107,12 @@ public class DataCenterDaoImpl extends GenericDaoBase implem } return listBy(sc); } - + @Override public List findChildZones(Object[] ids, String keyword){ - SearchCriteria sc = ChildZonesSearch.create(); - sc.setParameters("domainid", ids); - if (keyword != null) { + SearchCriteria sc = ChildZonesSearch.create(); + sc.setParameters("domainid", ids); + if (keyword != null) { SearchCriteria ssc = createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -120,71 +120,71 @@ public class DataCenterDaoImpl extends GenericDaoBase implem } return listBy(sc); } - + @Override public List listPublicZones(String keyword){ - SearchCriteria sc = PublicZonesSearch.create(); - if (keyword != null) { + SearchCriteria sc = PublicZonesSearch.create(); + if (keyword != null) { SearchCriteria ssc = createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); sc.addAnd("name", SearchCriteria.Op.SC, ssc); } - //sc.setParameters("domainId", domainId); + //sc.setParameters("domainId", domainId); return listBy(sc); } - + @Override public List findByKeyword(String keyword){ - SearchCriteria ssc = createSearchCriteria(); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + SearchCriteria ssc = createSearchCriteria(); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); return listBy(ssc); } - + @Override public void releaseVnet(String vnet, long dcId, long physicalNetworkId, long accountId, String reservationId) { _vnetAllocDao.release(vnet, physicalNetworkId, accountId, reservationId); } - + @Override public List findVnet(long dcId, long physicalNetworkId, String vnet) { - return _vnetAllocDao.findVnet(dcId, physicalNetworkId, vnet); + return _vnetAllocDao.findVnet(dcId, physicalNetworkId, vnet); } - + @Override public int countZoneVlans(long dcId, boolean onlyCountAllocated){ - return _vnetAllocDao.countZoneVlans(dcId, onlyCountAllocated); + return _vnetAllocDao.countZoneVlans(dcId, onlyCountAllocated); } @Override public void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId) { _ipAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); } - + @Override public void releasePrivateIpAddress(long nicId, String reservationId) { _ipAllocDao.releaseIpAddress(nicId, reservationId); } - + @Override public void releaseLinkLocalIpAddress(long nicId, String reservationId) { _LinkLocalIpAllocDao.releaseIpAddress(nicId, reservationId); } - + @Override public void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId) { - _LinkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); + _LinkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); } - + @Override public boolean deletePrivateIpAddressByPod(long podId) { - return _ipAllocDao.deleteIpAddressByPod(podId); + return _ipAllocDao.deleteIpAddressByPod(podId); } - + @Override public boolean deleteLinkLocalIpAddressByPod(long podId) { - return _LinkLocalIpAllocDao.deleteIpAddressByPod(podId); + return _LinkLocalIpAllocDao.deleteIpAddressByPod(podId); } @Override @@ -196,7 +196,7 @@ public class DataCenterDaoImpl extends GenericDaoBase implem return vo.getVnet(); } - + @Override public String allocatePodVlan(long podId, long accountId) { PodVlanVO vo = _podVlanAllocDao.take(podId, accountId); @@ -214,7 +214,7 @@ public class DataCenterDaoImpl extends GenericDaoBase implem @Override public String[] getNextAvailableMacAddressPair(long id, long mask) { SequenceFetcher fetch = SequenceFetcher.getInstance(); - + long seq = fetch.getNextSequence(Long.class, _tgMacAddress, id); seq = seq | _prefix | ((id & 0x7f) << 32); seq |= mask; @@ -234,43 +234,44 @@ public class DataCenterDaoImpl extends GenericDaoBase implem return new Pair(vo.getIpAddress(), vo.getMacAddress()); } + @Override public DataCenterIpAddressVO allocatePrivateIpAddress(long dcId, String reservationId) { - DataCenterIpAddressVO vo = _ipAllocDao.takeDataCenterIpAddress(dcId, reservationId); - return vo; + DataCenterIpAddressVO vo = _ipAllocDao.takeDataCenterIpAddress(dcId, reservationId); + return vo; } @Override public String allocateLinkLocalIpAddress(long dcId, long podId, long instanceId, String reservationId) { - DataCenterLinkLocalIpAddressVO vo = _LinkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId); + DataCenterLinkLocalIpAddressVO vo = _LinkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId); if (vo == null) { return null; } return vo.getIpAddress(); } - + @Override public void addVnet(long dcId, long physicalNetworkId, int start, int end) { _vnetAllocDao.add(dcId, physicalNetworkId, start, end); } - + @Override public void deleteVnet(long physicalNetworkId) { _vnetAllocDao.delete(physicalNetworkId); } - + @Override public List listAllocatedVnets(long physicalNetworkId) { return _vnetAllocDao.listAllocatedVnets(physicalNetworkId); } - + @Override public void addPrivateIpAddress(long dcId,long podId, String start, String end) { _ipAllocDao.addIpRange(dcId, podId, start, end); } - + @Override public void addLinkLocalIpAddress(long dcId,long podId, String start, String end) { - _LinkLocalIpAllocDao.addIpRange(dcId, podId, start, end); + _LinkLocalIpAllocDao.addIpRange(dcId, podId, start, end); } @Override @@ -278,7 +279,7 @@ public class DataCenterDaoImpl extends GenericDaoBase implem if (!super.configure(name, params)) { return false; } - + String value = (String)params.get("mac.address.prefix"); _prefix = (long)NumbersUtil.parseInt(value, 06) << 40; @@ -291,33 +292,33 @@ public class DataCenterDaoImpl extends GenericDaoBase implem } return true; } - + protected DataCenterDaoImpl() { super(); NameSearch = createSearchBuilder(); NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ); NameSearch.done(); - + ListZonesByDomainIdSearch = createSearchBuilder(); ListZonesByDomainIdSearch.and("domainId", ListZonesByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ); ListZonesByDomainIdSearch.done(); - + PublicZonesSearch = createSearchBuilder(); PublicZonesSearch.and("domainId", PublicZonesSearch.entity().getDomainId(), SearchCriteria.Op.NULL); PublicZonesSearch.done(); - + ChildZonesSearch = createSearchBuilder(); ChildZonesSearch.and("domainid", ChildZonesSearch.entity().getDomainId(), SearchCriteria.Op.IN); ChildZonesSearch.done(); - + DisabledZonesSearch = createSearchBuilder(); DisabledZonesSearch.and("allocationState", DisabledZonesSearch.entity().getAllocationState(), SearchCriteria.Op.EQ); DisabledZonesSearch.done(); - + TokenSearch = createSearchBuilder(); TokenSearch.and("zoneToken", TokenSearch.entity().getZoneToken(), SearchCriteria.Op.EQ); TokenSearch.done(); - + _tgMacAddress = _tgs.get("macAddress"); assert _tgMacAddress != null : "Couldn't get mac address table generator"; } @@ -334,7 +335,7 @@ public class DataCenterDaoImpl extends GenericDaoBase implem txn.commit(); return persisted; } - + @Override public void loadDetails(DataCenterVO zone) { Map details =_detailsDao.findDetails(zone.getId()); @@ -349,25 +350,25 @@ public class DataCenterDaoImpl extends GenericDaoBase implem } _detailsDao.persist(zone.getId(), details); } - + @Override public List listDisabledZones(){ - SearchCriteria sc = DisabledZonesSearch.create(); - sc.setParameters("allocationState", Grouping.AllocationState.Disabled); - - List dcs = listBy(sc); - - return dcs; + SearchCriteria sc = DisabledZonesSearch.create(); + sc.setParameters("allocationState", Grouping.AllocationState.Disabled); + + List dcs = listBy(sc); + + return dcs; } - + @Override public List listEnabledZones(){ - SearchCriteria sc = DisabledZonesSearch.create(); - sc.setParameters("allocationState", Grouping.AllocationState.Enabled); - - List dcs = listBy(sc); - - return dcs; + SearchCriteria sc = DisabledZonesSearch.create(); + sc.setParameters("allocationState", Grouping.AllocationState.Enabled); + + List dcs = listBy(sc); + + return dcs; } @Override @@ -380,20 +381,20 @@ public class DataCenterDaoImpl extends GenericDaoBase implem Long dcId = Long.parseLong(tokenOrIdOrName); return findById(dcId); } catch (NumberFormatException nfe) { - + } } } return result; } - + @Override public boolean remove(Long id) { Transaction txn = Transaction.currentTxn(); txn.start(); DataCenterVO zone = createForUpdate(); zone.setName(null); - + update(id, zone); boolean result = super.remove(id); diff --git a/server/src/com/cloud/network/rules/FirewallRuleVO.java b/server/src/com/cloud/network/rules/FirewallRuleVO.java index 14367a771aa..b64e8bf7b08 100644 --- a/server/src/com/cloud/network/rules/FirewallRuleVO.java +++ b/server/src/com/cloud/network/rules/FirewallRuleVO.java @@ -37,7 +37,6 @@ import javax.persistence.Transient; import com.cloud.api.Identity; import com.cloud.network.dao.FirewallRulesCidrsDaoImpl; -import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.db.GenericDao; import com.cloud.utils.net.NetUtils; @@ -46,68 +45,68 @@ import com.cloud.utils.net.NetUtils; @Inheritance(strategy=InheritanceType.JOINED) @DiscriminatorColumn(name="purpose", discriminatorType=DiscriminatorType.STRING, length=32) public class FirewallRuleVO implements Identity, FirewallRule { - @Inject protected final FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao; - + @Inject protected final FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao = null; + @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="id") long id; - + @GeneratedValue(strategy=GenerationType.AUTO) @Column(name=GenericDao.XID_COLUMN) String xId; @Column(name="domain_id", updatable=false) long domainId; - + @Column(name="account_id", updatable=false) long accountId; - + @Column(name="ip_address_id", updatable=false) Long sourceIpAddressId; - + @Column(name="start_port", updatable=false) Integer sourcePortStart; @Column(name="end_port", updatable=false) Integer sourcePortEnd; - + @Column(name="protocol", updatable=false) String protocol = NetUtils.TCP_PROTO; - + @Enumerated(value=EnumType.STRING) @Column(name="purpose") Purpose purpose; - + @Enumerated(value=EnumType.STRING) @Column(name="state") State state; - + @Column(name=GenericDao.CREATED_COLUMN) Date created; - + @Column(name="network_id") long networkId; - + @Column(name="icmp_code") Integer icmpCode; - + @Column(name="icmp_type") Integer icmpType; - + @Column(name="related") Long related; - + @Column(name="type") @Enumerated(value=EnumType.STRING) FirewallRuleType type; - + @Column(name="traffic_type") @Enumerated(value=EnumType.STRING) TrafficType trafficType; - - + + // This is a delayed load value. If the value is null, // then this field has not been loaded yet. // Call firewallrules dao to load it. @@ -168,7 +167,7 @@ public class FirewallRuleVO implements Identity, FirewallRule { public String getProtocol() { return protocol; } - + public void setState(State state) { this.state = state; } @@ -177,29 +176,29 @@ public class FirewallRuleVO implements Identity, FirewallRule { public Purpose getPurpose() { return purpose; } - + @Override public State getState() { return state; } - + @Override public long getNetworkId() { return networkId; } - + @Override public FirewallRuleType getType() { - return type; + return type; } public Date getCreated() { return created; } - + protected FirewallRuleVO() { - this.uuid = UUID.randomUUID().toString(); + this.uuid = UUID.randomUUID().toString(); } - + public FirewallRuleVO(String xId, Long ipAddressId, Integer portStart, Integer portEnd, String protocol, long networkId, long accountId, long domainId, Purpose purpose, List sourceCidrs, Integer icmpCode, Integer icmpType, Long related, TrafficType trafficType) { @@ -209,11 +208,11 @@ public class FirewallRuleVO implements Identity, FirewallRule { } this.accountId = accountId; this.domainId = domainId; - + if (ipAddressId == null) { assert (purpose == Purpose.NetworkACL) : "ipAddressId can be null for " + Purpose.NetworkACL + " only"; } - + this.sourceIpAddressId = ipAddressId; this.sourcePortStart = portStart; this.sourcePortEnd = portEnd; @@ -224,28 +223,28 @@ public class FirewallRuleVO implements Identity, FirewallRule { this.icmpCode = icmpCode; this.icmpType = icmpType; this.sourceCidrs = sourceCidrs; - + if (related != null) { assert (purpose == Purpose.Firewall) : "related field can be set for rule of purpose " + Purpose.Firewall + " only"; } - + this.related = related; - this.uuid = UUID.randomUUID().toString(); - this.type = FirewallRuleType.User; - this.trafficType = trafficType; + this.uuid = UUID.randomUUID().toString(); + this.type = FirewallRuleType.User; + this.trafficType = trafficType; } - - + + public FirewallRuleVO(String xId, long ipAddressId, int port, String protocol, long networkId, long accountId, long domainId, Purpose purpose, List sourceCidrs, Integer icmpCode, Integer icmpType, Long related) { this(xId, ipAddressId, port, port, protocol, networkId, accountId, domainId, purpose, sourceCidrs, icmpCode, icmpType, related, null); } - + @Override public String toString() { return new StringBuilder("Rule[").append(id).append("-").append(purpose).append("-").append(state).append("]").toString(); } - + @Override public Integer getIcmpCode() { return icmpCode; @@ -260,18 +259,18 @@ public class FirewallRuleVO implements Identity, FirewallRule { public Long getRelated() { return related; } - + @Override public String getUuid() { - return this.uuid; + return this.uuid; } - + public void setUuid(String uuid) { - this.uuid = uuid; + this.uuid = uuid; } - + public void setType(FirewallRuleType type) { - this.type = type; + this.type = type; } @Override