Skip to content

Commit 35914d6

Browse files
author
Alex Huang
committed
links are working
1 parent 862dff7 commit 35914d6

File tree

13 files changed

+482
-84
lines changed

13 files changed

+482
-84
lines changed

engine/api/pom.xml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
<!--
2-
Licensed to the Apache Software Foundation (ASF) under one
3-
or more contributor license agreements. See the NOTICE file
4-
distributed with this work for additional information
5-
regarding copyright ownership. The ASF licenses this file
6-
to you under the Apache License, Version 2.0 (the
7-
"License"); you may not use this file except in compliance
8-
with the License. You may obtain a copy of the License at
9-
10-
http://www.apache.org/licenses/LICENSE-2.0
11-
12-
Unless required by applicable law or agreed to in writing,
13-
software distributed under the License is distributed on an
14-
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
KIND, either express or implied. See the License for the
16-
specific language governing permissions and limitations
17-
under the License.
18-
-->
1+
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
2+
license agreements. See the NOTICE file distributed with this work for additional
3+
information regarding copyright ownership. The ASF licenses this file to
4+
you under the Apache License, Version 2.0 (the "License"); you may not use
5+
this file except in compliance with the License. You may obtain a copy of
6+
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
7+
by applicable law or agreed to in writing, software distributed under the
8+
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9+
OF ANY KIND, either express or implied. See the License for the specific
10+
language governing permissions and limitations under the License. -->
1911
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2012
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2113
<modelVersion>4.0.0</modelVersion>
@@ -42,8 +34,13 @@
4234
<groupId>org.eclipse.jetty</groupId>
4335
<artifactId>jetty-server</artifactId>
4436
</exclusion>
45-
</exclusions>
46-
</dependency>
37+
</exclusions>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.codehaus.jackson</groupId>
41+
<artifactId>jackson-jaxrs</artifactId>
42+
<version>1.9.9</version>
43+
</dependency>
4744
</dependencies>
4845
<build>
4946
<defaultGoal>install</defaultGoal>

engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceEntity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
*/
1919
package org.apache.cloudstack.engine.datacenter.entity.api;
2020

21+
import javax.ws.rs.GET;
2122
import javax.ws.rs.POST;
23+
import javax.ws.rs.Produces;
2224

2325
import org.apache.cloudstack.engine.entity.api.CloudStackEntity;
2426

@@ -29,6 +31,7 @@
2931
* This interface specifies the states and operations all physical
3032
* and virtual resources in the data center must implement.
3133
*/
34+
@Produces({"application/json", "application/xml"})
3235
public interface DataCenterResourceEntity extends CloudStackEntity, StateObject<DataCenterResourceEntity.State> {
3336

3437
/**
@@ -87,4 +90,8 @@ public enum Event {
8790
@POST
8891
boolean reactivate();
8992

93+
@Override
94+
@GET
95+
State getState();
96+
9097
}

engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222

2323
import javax.ws.rs.GET;
2424
import javax.ws.rs.Path;
25+
import javax.xml.bind.annotation.XmlRootElement;
2526

2627
import com.cloud.dc.DataCenter;
2728

2829
/**
2930
* Describes a zone and operations that can be done in a zone.
3031
*/
31-
@Path("zone/{zone-id}")
32+
@XmlRootElement(name="zone")
3233
public interface ZoneEntity extends DataCenterResourceEntity, DataCenter {
3334
@GET
35+
@Path("/pods")
3436
List<PodEntity> listPods();
37+
38+
List<String> listPodIds();
3539
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.engine.rest.datacenter.entity.api;
20+
21+
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
22+
23+
public class PodRestTO {
24+
25+
public String uuid;
26+
public String name;
27+
28+
public PodRestTO(PodEntity pod) {
29+
this.uuid = pod.getUuid();
30+
this.name = pod.getName();
31+
}
32+
33+
public PodRestTO() {
34+
}
35+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.engine.rest.datacenter.entity.api;
20+
21+
import java.net.URI;
22+
import java.util.List;
23+
24+
import javax.inject.Inject;
25+
import javax.ws.rs.GET;
26+
import javax.ws.rs.Path;
27+
import javax.ws.rs.PathParam;
28+
import javax.ws.rs.core.UriBuilder;
29+
30+
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
31+
import org.apache.cloudstack.engine.service.api.ProvisioningService;
32+
import org.springframework.stereotype.Service;
33+
34+
@Service("zoneService")
35+
@Path("/zone/{zoneid}")
36+
public class ZoneRestTO {
37+
@Inject
38+
protected static ProvisioningService s_provisioningService;
39+
40+
public String id;
41+
public URI uri;
42+
public String name;
43+
public String[] pods;
44+
45+
public ZoneRestTO(UriBuilder ub, ZoneEntity zone, URI uri) {
46+
this.id = zone.getUuid();
47+
this.name = zone.getName();
48+
this.uri = uri;
49+
List<String> podIds = zone.listPodIds();
50+
this.pods = new String[podIds.size()];
51+
this.pods = podIds.toArray(new String[podIds.size()]);
52+
}
53+
54+
public ZoneRestTO() {
55+
}
56+
57+
@GET
58+
@Path("/pods")
59+
public String[] listPods(@PathParam("zoneid") String zoneId) {
60+
return this.pods;
61+
}
62+
63+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.engine.rest.datacenter.entity.api;
20+
21+
public class ZoneRestTOs {
22+
23+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.engine.rest.service.api;
20+
21+
import java.util.Iterator;
22+
import java.util.List;
23+
24+
import javax.inject.Inject;
25+
import javax.ws.rs.GET;
26+
import javax.ws.rs.Path;
27+
import javax.ws.rs.PathParam;
28+
import javax.ws.rs.Produces;
29+
import javax.ws.rs.core.Context;
30+
import javax.ws.rs.core.UriBuilder;
31+
import javax.ws.rs.core.UriInfo;
32+
33+
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
34+
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
35+
import org.apache.cloudstack.engine.rest.datacenter.entity.api.PodRestTO;
36+
import org.apache.cloudstack.engine.rest.datacenter.entity.api.ZoneRestTO;
37+
import org.apache.cloudstack.engine.service.api.ProvisioningService;
38+
import org.springframework.stereotype.Component;
39+
import org.springframework.stereotype.Service;
40+
41+
42+
@Service("provisioningService")
43+
@Path("/provisioning")
44+
@Produces({"application/xml", "application/json"})
45+
@Component
46+
public class ProvisioningRestService {
47+
@Inject
48+
ProvisioningService _provisioningService;
49+
50+
@GET
51+
@Path("/{zoneid}")
52+
public ZoneRestTO getZone(@Context UriInfo ui, @PathParam("zoneid") String id) {
53+
UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone");
54+
ZoneEntity entity = _provisioningService.getZone(id);
55+
return new ZoneRestTO(ub, entity, ub.build(entity.getUuid()));
56+
}
57+
58+
@GET
59+
@Path("/zones")
60+
public ZoneRestTO[] listZones(@Context UriInfo ui) {
61+
List<ZoneEntity> zones = _provisioningService.listZones();
62+
ZoneRestTO[] tos = new ZoneRestTO[zones.size()];
63+
UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone");
64+
Iterator<ZoneEntity> it = zones.iterator();
65+
for (int i = 0; i < tos.length; i++) {
66+
ZoneEntity entity = it.next();
67+
tos[i] = new ZoneRestTO(ub, entity, ub.build(entity.getUuid()));
68+
}
69+
return tos;
70+
}
71+
72+
@GET
73+
@Path("/zone/{zoneid}/pods")
74+
public PodRestTO[] listPods(@PathParam("zoneid") String zoneId) {
75+
List<PodEntity> pods = _provisioningService.listPods();
76+
PodRestTO[] tos = new PodRestTO[pods.size()];
77+
Iterator<PodEntity> it = pods.iterator();
78+
for (int i = 0; i < tos.length; i++) {
79+
PodEntity pod = it.next();
80+
tos[i] = new PodRestTO(pod);
81+
}
82+
return tos;
83+
}
84+
}

engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,11 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
import javax.ws.rs.DELETE;
25-
import javax.ws.rs.GET;
26-
import javax.ws.rs.POST;
27-
import javax.ws.rs.Path;
28-
import javax.ws.rs.Produces;
29-
3024
import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
3125
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
3226
import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
3327
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
3428

35-
import com.cloud.dc.Pod;
3629
import com.cloud.host.Host;
3730
import com.cloud.host.Status;
3831
import com.cloud.storage.StoragePool;
@@ -42,56 +35,37 @@
4235
* ProvisioningService registers and deregisters physical and virtual
4336
* resources that the management server can use.
4437
*/
45-
@Path("/provision")
46-
@Produces({"application/json", "application/xml"})
4738
public interface ProvisioningService {
4839

49-
@POST
5040
StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details);
5141

52-
@POST
5342
ZoneEntity registerZone(String name, List<String> tags, Map<String, String> details);
5443

55-
@POST
5644
PodEntity registerPod(String name, List<String> tags, Map<String, String> details);
5745

58-
@POST
5946
ClusterEntity registerCluster(String name, List<String> tags, Map<String, String> details);
6047

61-
@POST
6248
String registerHost(String name, List<String> tags, Map<String, String> details);
6349

64-
@DELETE
6550
void deregisterStorage(String uuid);
6651

67-
@DELETE
6852
void deregisterZone();
6953

70-
@DELETE
7154
void deregisterPod();
7255

73-
@DELETE
7456
void deregisterCluster();
7557

76-
@DELETE
7758
void deregisterHost();
7859

7960
void changeState(String type, String entity, Status state);
8061

81-
@GET
82-
@Path("/hosts")
8362
List<Host> listHosts();
8463

85-
@GET
86-
@Path("/pods")
87-
List<Pod> listPods();
64+
List<PodEntity> listPods();
8865

89-
@GET
90-
@Path("/zones")
9166
List<ZoneEntity> listZones();
9267

93-
@GET
94-
@Path("/storages")
9568
List<StoragePool> listStorage();
9669

70+
ZoneEntity getZone(String id);
9771
}

0 commit comments

Comments
 (0)