cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [08/16] git commit: updated refs/heads/master to 67b753c
Date Mon, 28 Dec 2015 10:22:32 GMT
CLOUDSTACK-9074: API add Gateway Service Find method


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/eb889c0c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/eb889c0c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/eb889c0c

Branch: refs/heads/master
Commit: eb889c0c49313184609d31d4492c58eb0ff19f31
Parents: c676371
Author: nvazquez <nicolas.m.vazquez@gmail.com>
Authored: Wed Dec 9 10:55:30 2015 -0800
Committer: nvazquez <nicovazquez90@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../agent/api/FindL2GatewayServiceAnswer.java   | 38 +++++++++++
 .../agent/api/FindL2GatewayServiceCommand.java  | 46 +++++++++++++
 .../network/guru/NiciraNvpGuestNetworkGuru.java | 37 ++++++++++-
 .../network/nicira/GatewayServiceConfig.java    | 47 +++++++++++++
 .../network/nicira/L2GatewayServiceConfig.java  | 30 +++++++++
 .../cloud/network/nicira/NiciraConstants.java   |  2 +
 .../com/cloud/network/nicira/NiciraNvpApi.java  | 46 +++++++++----
 .../network/nicira/NiciraNvpApiException.java   | 25 +++++++
 .../cloud/network/nicira/NiciraRestClient.java  |  4 +-
 ...raNvpFindL2GatewayServiceCommandWrapper.java | 69 ++++++++++++++++++++
 .../guru/NiciraNvpGuestNetworkGuruTest.java     |  2 +-
 .../utils/rest/CloudstackRESTException.java     | 16 +++++
 .../cloud/utils/rest/RESTServiceConnector.java  |  2 +-
 13 files changed, 346 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceAnswer.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceAnswer.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceAnswer.java
new file mode 100644
index 0000000..16f24eb
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceAnswer.java
@@ -0,0 +1,38 @@
+//
+// 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 com.cloud.agent.api;
+
+public class FindL2GatewayServiceAnswer extends Answer {
+
+    private String gatewayServiceUuid;
+
+    public FindL2GatewayServiceAnswer(final Command command, final boolean success, final
String details, final String gatewayServiceUuid) {
+        super(command, success, details);
+        this.gatewayServiceUuid = gatewayServiceUuid;
+    }
+
+    public FindL2GatewayServiceAnswer(final Command command, final Exception e) {
+        super(command, e);
+    }
+
+    public String getGatewayServiceUuid() {
+        return gatewayServiceUuid;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceCommand.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceCommand.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceCommand.java
new file mode 100644
index 0000000..a3ec1dc
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceCommand.java
@@ -0,0 +1,46 @@
+//
+// 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 com.cloud.agent.api;
+
+import com.cloud.network.nicira.GatewayServiceConfig;
+import com.cloud.network.nicira.L2GatewayServiceConfig;
+
+public class FindL2GatewayServiceCommand extends Command {
+
+    private L2GatewayServiceConfig gatewayServiceConfig;
+
+    public FindL2GatewayServiceCommand(L2GatewayServiceConfig config) {
+        this.gatewayServiceConfig = config;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public GatewayServiceConfig getGatewayServiceConfig() {
+        return gatewayServiceConfig;
+    }
+
+    public void setGatewayServiceConfig(L2GatewayServiceConfig gatewayServiceConfig) {
+        this.gatewayServiceConfig = gatewayServiceConfig;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
index f83f8ee..551269c 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
@@ -36,6 +36,8 @@ import com.cloud.agent.api.DeleteLogicalRouterPortAnswer;
 import com.cloud.agent.api.DeleteLogicalRouterPortCommand;
 import com.cloud.agent.api.DeleteLogicalSwitchAnswer;
 import com.cloud.agent.api.DeleteLogicalSwitchCommand;
+import com.cloud.agent.api.FindL2GatewayServiceAnswer;
+import com.cloud.agent.api.FindL2GatewayServiceCommand;
 import com.cloud.agent.api.FindLogicalRouterPortAnswer;
 import com.cloud.agent.api.FindLogicalRouterPortCommand;
 import com.cloud.dc.DataCenter;
@@ -54,10 +56,10 @@ import com.cloud.network.Network.Service;
 import com.cloud.network.Network.State;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.NetworkProfile;
-import com.cloud.network.NiciraNvpNicMappingVO;
-import com.cloud.network.NiciraNvpRouterMappingVO;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.NiciraNvpDeviceVO;
+import com.cloud.network.NiciraNvpNicMappingVO;
+import com.cloud.network.NiciraNvpRouterMappingVO;
 import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.PhysicalNetwork.IsolationMethod;
 import com.cloud.network.dao.NetworkDao;
@@ -67,6 +69,7 @@ import com.cloud.network.dao.NiciraNvpNicMappingDao;
 import com.cloud.network.dao.NiciraNvpRouterMappingDao;
 import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.network.nicira.L2GatewayServiceConfig;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
 import com.cloud.resource.ResourceManager;
@@ -209,6 +212,16 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru implements
Netwo
         final String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
         final String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
 
+        if (offering.getGuestType().equals(GuestType.Shared)) {
+            try {
+                checkL2GatewayServiceSharedNetwork(niciraNvpHost);
+            }
+            catch (Exception e){
+                s_logger.error("L2 Gateway Service Issue: " + e.getMessage());
+                return null;
+            }
+        }
+
         final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid,
transportzoneisotype, name, context.getDomain().getName() + "-"
                 + context.getAccount().getAccountName());
         final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(),
cmd);
@@ -230,6 +243,26 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru implements
Netwo
         return implemented;
     }
 
+    private void checkL2GatewayServiceSharedNetwork(HostVO niciraNvpHost) throws Exception
{
+        String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid");
+        if (l2GatewayServiceUuid == null){
+            throw new Exception("No L2 Gateway Service found");
+        }
+        else {
+            final FindL2GatewayServiceCommand cmdL2GWService = new FindL2GatewayServiceCommand(new
L2GatewayServiceConfig(l2GatewayServiceUuid));
+            final FindL2GatewayServiceAnswer answerL2GWService = (FindL2GatewayServiceAnswer)
agentMgr.easySend(niciraNvpHost.getId(), cmdL2GWService);
+            if (answerL2GWService == null || !answerL2GWService.getResult()){
+                throw new Exception("No L2 Gateway Service found with uuid " + l2GatewayServiceUuid);
+            }
+            else {
+                String uuidFound = answerL2GWService.getGatewayServiceUuid();
+                if (! uuidFound.equals(l2GatewayServiceUuid)){
+                    throw new Exception("Found L2 Gateway Service " + uuidFound + " instead
of " + l2GatewayServiceUuid);
+                }
+            }
+        }
+    }
+
     @Override
     public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile
vm, final DeployDestination dest, final ReservationContext context)
             throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException
{

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/GatewayServiceConfig.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/GatewayServiceConfig.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/GatewayServiceConfig.java
new file mode 100644
index 0000000..abfd273
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/GatewayServiceConfig.java
@@ -0,0 +1,47 @@
+//
+// 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 com.cloud.network.nicira;
+
+import java.io.Serializable;
+
+public abstract class GatewayServiceConfig implements Serializable {
+
+    private String uuid;
+    private String displayName;
+    private String type;
+
+    public GatewayServiceConfig(String uuid, String type) {
+        this.uuid = uuid;
+        this.type = type;
+    }
+
+    public String getUuid() {
+        return uuid;
+    }
+
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayServiceConfig.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayServiceConfig.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayServiceConfig.java
new file mode 100644
index 0000000..7f2a41a
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayServiceConfig.java
@@ -0,0 +1,30 @@
+//
+// 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 com.cloud.network.nicira;
+
+public class L2GatewayServiceConfig extends GatewayServiceConfig {
+
+    private static final String L2GWTServiceConfigType = "L2GatewayServiceConfig";
+
+    public L2GatewayServiceConfig(String uuid) {
+        super(uuid, L2GWTServiceConfigType);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
index d5f7ca6..f89b8ad 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
@@ -25,6 +25,7 @@ public class NiciraConstants {
     public static final String ACL_URI_PREFIX = "/ws.v1/acl";
     public static final String SWITCH_URI_PREFIX = "/ws.v1/lswitch";
     public static final String ROUTER_URI_PREFIX = "/ws.v1/lrouter";
+    public static final String GATEWAY_SERVICE_PREFIX = "/ws.v1/gateway-service";
     public static final String LOGIN_URL = "/ws.v1/login";
     public static final String CONTROL_CLUSTER_STATUS_URL = "/ws.v1/control-cluster/status";
 
@@ -39,5 +40,6 @@ public class NiciraConstants {
     public static final String WILDCARD_QUERY_PARAMETER = "*";
     public static final String UUID_QUERY_PARAMETER = "uuid";
     public static final String FIELDS_QUERY_PARAMETER = "fields";
+    public static final String TYPES_QUERY_PARAMETER = "types";
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
index b1113a2..293c5a8 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
@@ -42,6 +42,7 @@ public class NiciraNvpApi {
 
     private static final String SWITCH_URI_PREFIX = NiciraConstants.SWITCH_URI_PREFIX;
     private static final String ROUTER_URI_PREFIX = NiciraConstants.ROUTER_URI_PREFIX;
+    private static final String GATEWAY_SERVICE_PREFIX = NiciraConstants.GATEWAY_SERVICE_PREFIX;
 
     private static final String ATTACHMENT_PATH_SEGMENT = NiciraConstants.ATTACHMENT_PATH_SEGMENT;
     private static final String NAT_PATH_SEGMENT = NiciraConstants.NAT_PATH_SEGMENT;
@@ -51,6 +52,7 @@ public class NiciraNvpApi {
     private static final String WILDCARD_QUERY_PARAMETER = NiciraConstants.WILDCARD_QUERY_PARAMETER;
     private static final String UUID_QUERY_PARAMETER = NiciraConstants.UUID_QUERY_PARAMETER;
     private static final String FIELDS_QUERY_PARAMETER = NiciraConstants.FIELDS_QUERY_PARAMETER;
+    private static final String TYPES_QUERY_PARAMETER = NiciraConstants.TYPES_QUERY_PARAMETER;
 
     private static final int DEFAULT_MAX_RETRIES = 5;
 
@@ -131,7 +133,7 @@ public class NiciraNvpApi {
         try {
             createdEntity = restConnector.executeCreateObject(entity, uri, Collections.<String,
String> emptyMap());
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
 
         return createdEntity;
@@ -157,7 +159,7 @@ public class NiciraNvpApi {
         try {
             entities = restConnector.executeRetrieveObject(listTypeMap.get(clazz), uri, params);
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
 
         if (entities == null) {
@@ -190,7 +192,7 @@ public class NiciraNvpApi {
         try {
             restConnector.executeUpdateObject(item, uri, Collections.<String, String>
emptyMap());
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -215,7 +217,7 @@ public class NiciraNvpApi {
         try {
             restConnector.executeDeleteObject(uri);
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -394,7 +396,7 @@ public class NiciraNvpApi {
             }.getType();
             niciraList = restConnector.executeRetrieveObject(niciraListType, uri, params);
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
 
         final List<LogicalSwitchPort> lspl = niciraList.getResults();
@@ -413,7 +415,7 @@ public class NiciraNvpApi {
         try {
             return restConnector.executeRetrieveObject(ControlClusterStatus.class, uri, new
HashMap<String, String>());
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -427,7 +429,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalSwitchPort>> executeRetrieveObject(niciraListType,
uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -441,7 +443,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType,
uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -522,7 +524,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType,
uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -536,7 +538,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType,
uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -549,7 +551,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<NatRule>> executeRetrieveObject(niciraListType,
uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -564,10 +566,30 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType,
uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
+    public List<L2GatewayServiceConfig> findL2GatewayServiceByUuidAndType(final String
gatewayServiceUuid, final String serviceConfigType) throws NiciraNvpApiException{
+        final String uri = buildGatewayServiceUri();
+        final Map<String, String> params = buildBasicParametersMap(WILDCARD_QUERY_PARAMETER);
+        params.put(UUID_QUERY_PARAMETER, gatewayServiceUuid);
+        params.put(TYPES_QUERY_PARAMETER, serviceConfigType);
+
+        try {
+            final Type niciraListType = new TypeToken<NiciraNvpList<L2GatewayServiceConfig>>()
{
+            }.getType();
+            return restConnector.<NiciraNvpList<L2GatewayServiceConfig>> executeRetrieveObject(niciraListType,
uri, params).getResults();
+        }
+        catch (final CloudstackRESTException e){
+            throw new NiciraNvpApiException(e, e.getErrorCode());
+        }
+    }
+
+    private static String buildGatewayServiceUri(){
+        return GATEWAY_SERVICE_PREFIX;
+    }
+
     private static Map<String, String> buildBasicParametersMap(final String fieldsQueryValue)
{
         final Map<String, String> params = new HashMap<String, String>();
         params.put(FIELDS_QUERY_PARAMETER, fieldsQueryValue);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
index 0d27820..f8b3c07 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
@@ -21,6 +21,8 @@ package com.cloud.network.nicira;
 
 public class NiciraNvpApiException extends Exception {
 
+    private int errorCode;
+
     public NiciraNvpApiException() {
     }
 
@@ -36,4 +38,27 @@ public class NiciraNvpApiException extends Exception {
         super(message, cause);
     }
 
+    public NiciraNvpApiException(final String message, final int errorCode){
+        super(message);
+        this.errorCode = errorCode;
+    }
+
+    public NiciraNvpApiException(final Throwable cause, final int errorCode) {
+        super(cause);
+        this.errorCode = errorCode;
+    }
+
+    public NiciraNvpApiException(final String message, final Throwable cause, final int errorCode)
{
+        super(message, cause);
+        this.errorCode = errorCode;
+    }
+
+    public int getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(int errorCode) {
+        this.errorCode = errorCode;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
index b850c4b..fb66066 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
@@ -92,9 +92,9 @@ public class NiciraRestClient extends BasicRestClient {
         } else if (HttpStatusCodeHelper.isSuccess(statusCode)) {
             return handleSuccessResponse(request, response);
         } else if (HttpStatusCodeHelper.isConflict(statusCode)) {
-            throw new CloudstackRESTException("Conflict: " + statusLine.getReasonPhrase());
+            throw new CloudstackRESTException("Conflict: " + statusLine.getReasonPhrase(),
statusCode);
         } else {
-            throw new CloudstackRESTException("Unexpected status code: " + statusCode);
+            throw new CloudstackRESTException("Unexpected status code: " + statusCode, statusCode);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java
new file mode 100644
index 0000000..621f503
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java
@@ -0,0 +1,69 @@
+//
+// 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 com.cloud.network.resource.wrapper;
+
+import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.FindL2GatewayServiceAnswer;
+import com.cloud.agent.api.FindL2GatewayServiceCommand;
+import com.cloud.network.nicira.GatewayServiceConfig;
+import com.cloud.network.nicira.L2GatewayServiceConfig;
+import com.cloud.network.nicira.NiciraNvpApi;
+import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.utils.CommandRetryUtility;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+
+@ResourceWrapper(handles =  FindL2GatewayServiceCommand.class)
+public class NiciraNvpFindL2GatewayServiceCommandWrapper extends CommandWrapper<FindL2GatewayServiceCommand,
Answer, NiciraNvpResource> {
+
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpFindL2GatewayServiceCommandWrapper.class);
+
+    @Override
+    public Answer execute(FindL2GatewayServiceCommand command, NiciraNvpResource niciraNvpResource)
{
+        final GatewayServiceConfig config = command.getGatewayServiceConfig();
+        final String uuid = config.getUuid();
+        final String type = config.getType();
+        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
+
+        s_logger.info("Looking for L2 Gateway Service " + uuid + " of type " + type);
+
+        try {
+            List<L2GatewayServiceConfig> lstGW = niciraNvpApi.findL2GatewayServiceByUuidAndType(uuid,
type);
+            if (lstGW.size() == 0) {
+                return new FindL2GatewayServiceAnswer(command, false, "L2 Gateway Service
not found", null);
+            } else {
+                return new FindL2GatewayServiceAnswer(command, true, "L2 Gateway Service
" + lstGW.get(0).getDisplayName()+ " found", lstGW.get(0).getUuid());
+            }
+        } catch (NiciraNvpApiException e) {
+            s_logger.error("Error finding Gateway Service due to: " + e.getMessage());
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, FindL2GatewayServiceAnswer.class, e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
index d7c83b4..f1737c1 100644
--- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
+++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
@@ -473,4 +473,4 @@ public class NiciraNvpGuestNetworkGuruTest {
         verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command)any());
         verify(implementednetwork, times(1)).setBroadcastUri(null);
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java b/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java
index 2078d57..9b703c6 100644
--- a/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java
+++ b/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java
@@ -22,6 +22,8 @@ package com.cloud.utils.rest;
 @SuppressWarnings("serial")
 public class CloudstackRESTException extends Exception {
 
+    private int errorCode;
+
     public CloudstackRESTException(final String message) {
         super(message);
     }
@@ -30,4 +32,18 @@ public class CloudstackRESTException extends Exception {
         super(message, cause);
     }
 
+    public CloudstackRESTException(final String message, final int errorCode) {
+        super(message);
+        this.errorCode = errorCode;
+    }
+
+    public CloudstackRESTException(final String message, final Throwable cause, final int
errorCode) {
+        super(message, cause);
+        this.errorCode = errorCode;
+    }
+
+    public int getErrorCode() {
+        return errorCode;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java b/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java
index fc5bae3..ffa2905 100644
--- a/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java
+++ b/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java
@@ -127,7 +127,7 @@ public class RESTServiceConnector {
         final HttpEntity entity = response.getEntity();
         try {
             final String stringEntity = EntityUtils.toString(entity);
-            s_logger.debug("Response entity: " + stringEntity);
+            //s_logger.debug("Response entity: " + stringEntity);
             EntityUtils.consumeQuietly(entity);
             return gson.fromJson(stringEntity, type);
         } catch (final IOException e) {


Mime
View raw message