Skip to content

Commit eb889c0

Browse files
committed
CLOUDSTACK-9074: API add Gateway Service Find method
1 parent c676371 commit eb889c0

13 files changed

Lines changed: 346 additions & 18 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
20+
package com.cloud.agent.api;
21+
22+
public class FindL2GatewayServiceAnswer extends Answer {
23+
24+
private String gatewayServiceUuid;
25+
26+
public FindL2GatewayServiceAnswer(final Command command, final boolean success, final String details, final String gatewayServiceUuid) {
27+
super(command, success, details);
28+
this.gatewayServiceUuid = gatewayServiceUuid;
29+
}
30+
31+
public FindL2GatewayServiceAnswer(final Command command, final Exception e) {
32+
super(command, e);
33+
}
34+
35+
public String getGatewayServiceUuid() {
36+
return gatewayServiceUuid;
37+
}
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
20+
package com.cloud.agent.api;
21+
22+
import com.cloud.network.nicira.GatewayServiceConfig;
23+
import com.cloud.network.nicira.L2GatewayServiceConfig;
24+
25+
public class FindL2GatewayServiceCommand extends Command {
26+
27+
private L2GatewayServiceConfig gatewayServiceConfig;
28+
29+
public FindL2GatewayServiceCommand(L2GatewayServiceConfig config) {
30+
this.gatewayServiceConfig = config;
31+
}
32+
33+
@Override
34+
public boolean executeInSequence() {
35+
return false;
36+
}
37+
38+
public GatewayServiceConfig getGatewayServiceConfig() {
39+
return gatewayServiceConfig;
40+
}
41+
42+
public void setGatewayServiceConfig(L2GatewayServiceConfig gatewayServiceConfig) {
43+
this.gatewayServiceConfig = gatewayServiceConfig;
44+
}
45+
46+
}

plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import com.cloud.agent.api.DeleteLogicalRouterPortCommand;
3737
import com.cloud.agent.api.DeleteLogicalSwitchAnswer;
3838
import com.cloud.agent.api.DeleteLogicalSwitchCommand;
39+
import com.cloud.agent.api.FindL2GatewayServiceAnswer;
40+
import com.cloud.agent.api.FindL2GatewayServiceCommand;
3941
import com.cloud.agent.api.FindLogicalRouterPortAnswer;
4042
import com.cloud.agent.api.FindLogicalRouterPortCommand;
4143
import com.cloud.dc.DataCenter;
@@ -54,10 +56,10 @@
5456
import com.cloud.network.Network.State;
5557
import com.cloud.network.NetworkModel;
5658
import com.cloud.network.NetworkProfile;
57-
import com.cloud.network.NiciraNvpNicMappingVO;
58-
import com.cloud.network.NiciraNvpRouterMappingVO;
5959
import com.cloud.network.Networks.BroadcastDomainType;
6060
import com.cloud.network.NiciraNvpDeviceVO;
61+
import com.cloud.network.NiciraNvpNicMappingVO;
62+
import com.cloud.network.NiciraNvpRouterMappingVO;
6163
import com.cloud.network.PhysicalNetwork;
6264
import com.cloud.network.PhysicalNetwork.IsolationMethod;
6365
import com.cloud.network.dao.NetworkDao;
@@ -67,6 +69,7 @@
6769
import com.cloud.network.dao.NiciraNvpRouterMappingDao;
6870
import com.cloud.network.dao.PhysicalNetworkDao;
6971
import com.cloud.network.dao.PhysicalNetworkVO;
72+
import com.cloud.network.nicira.L2GatewayServiceConfig;
7073
import com.cloud.offering.NetworkOffering;
7174
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
7275
import com.cloud.resource.ResourceManager;
@@ -209,6 +212,16 @@ public Network implement(final Network network, final NetworkOffering offering,
209212
final String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
210213
final String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
211214

215+
if (offering.getGuestType().equals(GuestType.Shared)) {
216+
try {
217+
checkL2GatewayServiceSharedNetwork(niciraNvpHost);
218+
}
219+
catch (Exception e){
220+
s_logger.error("L2 Gateway Service Issue: " + e.getMessage());
221+
return null;
222+
}
223+
}
224+
212225
final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name, context.getDomain().getName() + "-"
213226
+ context.getAccount().getAccountName());
214227
final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
@@ -230,6 +243,26 @@ public Network implement(final Network network, final NetworkOffering offering,
230243
return implemented;
231244
}
232245

246+
private void checkL2GatewayServiceSharedNetwork(HostVO niciraNvpHost) throws Exception {
247+
String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid");
248+
if (l2GatewayServiceUuid == null){
249+
throw new Exception("No L2 Gateway Service found");
250+
}
251+
else {
252+
final FindL2GatewayServiceCommand cmdL2GWService = new FindL2GatewayServiceCommand(new L2GatewayServiceConfig(l2GatewayServiceUuid));
253+
final FindL2GatewayServiceAnswer answerL2GWService = (FindL2GatewayServiceAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmdL2GWService);
254+
if (answerL2GWService == null || !answerL2GWService.getResult()){
255+
throw new Exception("No L2 Gateway Service found with uuid " + l2GatewayServiceUuid);
256+
}
257+
else {
258+
String uuidFound = answerL2GWService.getGatewayServiceUuid();
259+
if (! uuidFound.equals(l2GatewayServiceUuid)){
260+
throw new Exception("Found L2 Gateway Service " + uuidFound + " instead of " + l2GatewayServiceUuid);
261+
}
262+
}
263+
}
264+
}
265+
233266
@Override
234267
public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
235268
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
20+
package com.cloud.network.nicira;
21+
22+
import java.io.Serializable;
23+
24+
public abstract class GatewayServiceConfig implements Serializable {
25+
26+
private String uuid;
27+
private String displayName;
28+
private String type;
29+
30+
public GatewayServiceConfig(String uuid, String type) {
31+
this.uuid = uuid;
32+
this.type = type;
33+
}
34+
35+
public String getUuid() {
36+
return uuid;
37+
}
38+
39+
public String getDisplayName() {
40+
return displayName;
41+
}
42+
43+
public String getType() {
44+
return type;
45+
}
46+
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
20+
package com.cloud.network.nicira;
21+
22+
public class L2GatewayServiceConfig extends GatewayServiceConfig {
23+
24+
private static final String L2GWTServiceConfigType = "L2GatewayServiceConfig";
25+
26+
public L2GatewayServiceConfig(String uuid) {
27+
super(uuid, L2GWTServiceConfigType);
28+
}
29+
30+
}

plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class NiciraConstants {
2525
public static final String ACL_URI_PREFIX = "/ws.v1/acl";
2626
public static final String SWITCH_URI_PREFIX = "/ws.v1/lswitch";
2727
public static final String ROUTER_URI_PREFIX = "/ws.v1/lrouter";
28+
public static final String GATEWAY_SERVICE_PREFIX = "/ws.v1/gateway-service";
2829
public static final String LOGIN_URL = "/ws.v1/login";
2930
public static final String CONTROL_CLUSTER_STATUS_URL = "/ws.v1/control-cluster/status";
3031

@@ -39,5 +40,6 @@ public class NiciraConstants {
3940
public static final String WILDCARD_QUERY_PARAMETER = "*";
4041
public static final String UUID_QUERY_PARAMETER = "uuid";
4142
public static final String FIELDS_QUERY_PARAMETER = "fields";
43+
public static final String TYPES_QUERY_PARAMETER = "types";
4244

4345
}

0 commit comments

Comments
 (0)