cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [05/16] git commit: updated refs/heads/master to 67b753c
Date Mon, 28 Dec 2015 10:22:29 GMT
CLOUDSTACK-9074: New NiciraNVP classes to support Shared Networks


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

Branch: refs/heads/master
Commit: 06d5b46e538ba4d1a88995bff4aef5fe2e5275e7
Parents: 8149081
Author: nvazquez <nicolas.m.vazquez@gmail.com>
Authored: Tue Dec 1 11:50:52 2015 -0800
Committer: nvazquez <nicovazquez90@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../guru/NetworkGuruAdditionalFunctions.java    |  12 ++
 .../api/ConfigureSharedNetworkUuidAnswer.java   |  32 +++
 .../api/ConfigureSharedNetworkUuidCommand.java  |  85 ++++++++
 .../api/ConfigureSharedNetworkVlanIdAnswer.java |  31 +++
 .../ConfigureSharedNetworkVlanIdCommand.java    |  84 ++++++++
 .../network/nicira/L2GatewayAttachment.java     |  53 +++++
 ...onfigureSharedNetworkUuidCommandWrapper.java | 196 +++++++++++++++++++
 ...figureSharedNetworkVlanIdCommandWrapper.java | 118 +++++++++++
 8 files changed, 611 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java b/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
new file mode 100644
index 0000000..43a1871
--- /dev/null
+++ b/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
@@ -0,0 +1,12 @@
+package com.cloud.network.guru;
+
+import java.util.Map;
+
+public interface NetworkGuruAdditionalFunctions {
+
+    public static final String NSX_LSWITCH_UUID = "logicalswitch";
+    public static final String NSX_LSWITCHPORT_UUID = "logicalswitchport";
+
+    void finalizeNetworkDesign(long networkId, String vlanIdAsUUID);
+    Map<String, ? extends Object> listAdditionalNicParams(String nicUuid);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidAnswer.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidAnswer.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidAnswer.java
new file mode 100644
index 0000000..46fc8f5
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidAnswer.java
@@ -0,0 +1,32 @@
+//
+// 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 ConfigureSharedNetworkUuidAnswer extends Answer {
+
+    public ConfigureSharedNetworkUuidAnswer(final Command command, final boolean success,
final String details) {
+        super(command, success, details);
+    }
+
+    public ConfigureSharedNetworkUuidAnswer(final Command command, final Exception e) {
+        super(command, e);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidCommand.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidCommand.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidCommand.java
new file mode 100644
index 0000000..4dd361b
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidCommand.java
@@ -0,0 +1,85 @@
+//
+// 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 ConfigureSharedNetworkUuidCommand extends Command {
+
+    private String logicalRouterUuid;
+    private String logicalSwitchUuid;
+    private String portIpAddress;
+    private String ownerName;
+    private long networkId;
+
+    public ConfigureSharedNetworkUuidCommand(final String logicalRouterUuid, final String
logicalSwitchUuid,
+            final String portIpAddress, final String ownerName, final long networkId) {
+        super();
+        this.logicalRouterUuid = logicalRouterUuid;
+        this.logicalSwitchUuid = logicalSwitchUuid;
+        this.portIpAddress = portIpAddress;
+        this.ownerName = ownerName;
+        this.networkId = networkId;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public String getLogicalRouterUuid() {
+        return logicalRouterUuid;
+    }
+
+    public void setLogicalRouterUuid(String logicalRouterUuid) {
+        this.logicalRouterUuid = logicalRouterUuid;
+    }
+
+    public String getLogicalSwitchUuid() {
+        return logicalSwitchUuid;
+    }
+
+    public void setLogicalSwitchUuid(String logicalSwitchUuid) {
+        this.logicalSwitchUuid = logicalSwitchUuid;
+    }
+
+    public String getPortIpAddress() {
+        return portIpAddress;
+    }
+
+    public void setPortIpAddress(String portIpAddress) {
+        this.portIpAddress = portIpAddress;
+    }
+
+    public String getOwnerName() {
+        return ownerName;
+    }
+
+    public void setOwnerName(String ownerName) {
+        this.ownerName = ownerName;
+    }
+
+    public long getNetworkId() {
+        return networkId;
+    }
+
+    public void setNetworkId(long networkId) {
+        this.networkId = networkId;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdAnswer.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdAnswer.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdAnswer.java
new file mode 100644
index 0000000..1295569
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdAnswer.java
@@ -0,0 +1,31 @@
+//
+// 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 ConfigureSharedNetworkVlanIdAnswer extends Answer {
+
+    public ConfigureSharedNetworkVlanIdAnswer(final Command command, final boolean success,
final String details) {
+        super(command, success, details);
+    }
+
+    public ConfigureSharedNetworkVlanIdAnswer(final Command command, final Exception e) {
+        super(command, e);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdCommand.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdCommand.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdCommand.java
new file mode 100644
index 0000000..c6837dd
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdCommand.java
@@ -0,0 +1,84 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.agent.api;
+
+public class ConfigureSharedNetworkVlanIdCommand extends Command {
+
+    private String logicalSwitchUuid;
+    private String l2GatewayServiceUuid;
+    private long vlanId;
+    private String ownerName;
+    private long networkId;
+
+    public ConfigureSharedNetworkVlanIdCommand(final String logicalSwitchUuid, final String
l2GatewayServiceUuid,
+            final long vlanId, final String ownerName, final long networkId) {
+        this.logicalSwitchUuid = logicalSwitchUuid;
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+        this.vlanId = vlanId;
+        this.ownerName = ownerName;
+        this.networkId = networkId;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public String getLogicalSwitchUuid() {
+        return logicalSwitchUuid;
+    }
+
+    public void setLogicalSwitchUuid(String logicalSwitchUuid) {
+        this.logicalSwitchUuid = logicalSwitchUuid;
+    }
+
+    public String getL2GatewayServiceUuid() {
+        return l2GatewayServiceUuid;
+    }
+
+    public void setL2GatewayServiceUuid(String l2GatewayServiceUuid) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+    }
+
+    public long getVlanId() {
+        return vlanId;
+    }
+
+    public void setVlanId(long vlanId) {
+        this.vlanId = vlanId;
+    }
+
+    public String getOwnerName() {
+        return ownerName;
+    }
+
+    public void setOwnerName(String ownerName) {
+        this.ownerName = ownerName;
+    }
+
+    public long getNetworkId() {
+        return networkId;
+    }
+
+    public void setNetworkId(long networkId) {
+        this.networkId = networkId;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayAttachment.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayAttachment.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayAttachment.java
new file mode 100644
index 0000000..2ef294e
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayAttachment.java
@@ -0,0 +1,53 @@
+//
+// 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 L2GatewayAttachment extends Attachment {
+
+    private String l2GatewayServiceUuid;
+    private final String type = "L2GatewayAttachment";
+    private Long vlanId;
+
+    public L2GatewayAttachment(String l2GatewayServiceUuid) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+    }
+
+    public L2GatewayAttachment(final String l2GatewayServiceUuid, final long vlanId) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+        this.vlanId = vlanId;
+    }
+
+    public String getL2GatewayServiceUuid() {
+        return l2GatewayServiceUuid;
+    }
+    public void setL2GatewayServiceUuid(String l2GatewayServiceUuid) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+    }
+    public Long getVlanId() {
+        return vlanId;
+    }
+    public void setVlanId(Long vlanId) {
+        this.vlanId = vlanId;
+    }
+    public String getType() {
+        return type;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java
new file mode 100644
index 0000000..3a1d2cb
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java
@@ -0,0 +1,196 @@
+//
+// 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.NAME_MAX_LEN;
+import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer;
+import com.cloud.agent.api.ConfigureSharedNetworkUuidCommand;
+import com.cloud.network.nicira.LogicalRouterPort;
+import com.cloud.network.nicira.LogicalSwitch;
+import com.cloud.network.nicira.LogicalSwitchPort;
+import com.cloud.network.nicira.NiciraNvpApi;
+import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.nicira.NiciraNvpTag;
+import com.cloud.network.nicira.PatchAttachment;
+import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.utils.CommandRetryUtility;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.rest.HttpStatusCodeHelper;
+
+@ResourceWrapper(handles =  ConfigureSharedNetworkUuidCommand.class)
+public final class NiciraNvpConfigureSharedNetworkUuidCommandWrapper extends CommandWrapper<ConfigureSharedNetworkUuidCommand,
Answer, NiciraNvpResource>{
+
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigureSharedNetworkUuidCommandWrapper.class);
+
+    @Override
+    public Answer execute(ConfigureSharedNetworkUuidCommand command, NiciraNvpResource niciraNvpResource)
{
+        final String logicalRouterUuid = command.getLogicalRouterUuid();
+        final String logicalSwitchUuid = command.getLogicalSwitchUuid();
+        final String portIpAddress = command.getPortIpAddress();
+        final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
+        tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
+        final long networkId = command.getNetworkId();
+
+        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
+
+        s_logger.debug("Attaching Logical Switch " + logicalSwitchUuid + " on Logical Router
" + logicalRouterUuid + " for Shared Network " + networkId);
+
+        //Step 1: Get lSwitch displayName
+        s_logger.info("Looking for Logical Switch " + logicalSwitchUuid + " display name");
+        String logicalSwitchDisplayName;
+        try{
+            List<LogicalSwitch> lSwitchList = niciraNvpApi.findLogicalSwitch(logicalSwitchUuid);
+            if (lSwitchList != null){
+                if (lSwitchList.size() == 1){
+                    logicalSwitchDisplayName = lSwitchList.get(0).getDisplayName();
+                }
+                else {
+                    s_logger.error("More than one Logical Switch found with uuid " + logicalSwitchUuid);
+                    throw new CloudRuntimeException("More than one Logical Switch found with
uuid=" + logicalSwitchUuid);
+                }
+            }
+            else {
+                s_logger.error("Logical Switch " + logicalSwitchUuid + " not found");
+                throw new CloudRuntimeException("Logical Switch " + logicalSwitchUuid + "
not found");
+            }
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Logical Switch " + logicalSwitchUuid + " not found, retrying");
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, ConfigureSharedNetworkUuidAnswer.class, e);
+        }
+        catch (CloudRuntimeException e){
+            s_logger.info("Shared network UUID vlan id failed due to : " + e.getMessage());
+            return new ConfigureSharedNetworkUuidAnswer(command, false, e.getMessage());
+        }
+        s_logger.info("Found display name " + logicalSwitchDisplayName + " for Logical Switch
" + logicalSwitchUuid);
+
+
+        //Step 2: Create lRouterPort
+        s_logger.debug("Creating Logical Router Port in Logical Router " + logicalRouterUuid);
+        LogicalRouterPort lRouterPort = null;
+        try {
+            lRouterPort = new LogicalRouterPort();
+            lRouterPort.setAdminStatusEnabled(true);
+            lRouterPort.setDisplayName(niciraNvpResource.truncate(logicalSwitchDisplayName
+ "-uplink", NAME_MAX_LEN));
+            lRouterPort.setTags(tags);
+            final List<String> ipAddresses = new ArrayList<String>();
+            ipAddresses.add(portIpAddress);
+            lRouterPort.setIpAddresses(ipAddresses);
+            lRouterPort = niciraNvpApi.createLogicalRouterPort(logicalRouterUuid, lRouterPort);
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not create Logical Router Port on Logical Router " + logicalRouterUuid
+ " due to: " + e.getMessage() + ", retrying");
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName()
+ ") successfully created in Logical Router " + logicalRouterUuid);
+
+
+        //Step 3: Create lSwitchPort
+        s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid
+ " (" + logicalSwitchDisplayName + ")");
+        LogicalSwitchPort lSwitchPort = null;
+        try {
+            lSwitchPort = new LogicalSwitchPort(niciraNvpResource.truncate("lrouter-uplink",
NAME_MAX_LEN), tags, true);
+            lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid
+ " (" + logicalSwitchDisplayName + ")  due to: " + e.getMessage());
+            cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName()
+ ") successfully created in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName
+ ")");
+
+
+        //Step 4: Attach lRouterPort to lSwitchPort with a PatchAttachment
+        s_logger.debug("Attaching Logical Router Port " + lRouterPort.getUuid() + " (" +
lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " ("
+ lSwitchPort.getDisplayName() + ") with a PatchAttachment");
+        try {
+            niciraNvpApi.updateLogicalRouterPortAttachment(logicalRouterUuid, lRouterPort.getUuid(),
new PatchAttachment(lSwitchPort.getUuid()));
+        }
+        catch (NiciraNvpApiException e) {
+            s_logger.warn("Could not attach Logical Router Port " + lRouterPort.getUuid()
+ " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid()
+ " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying");
+            cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
+            cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName()
+ ") successfully attached to to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName()
+ ") with a PatchAttachment");
+
+
+        //Step 5: Attach lSwitchPort to lRouterPort with a PatchAttachment
+        s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" +
lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " ("
+ lRouterPort.getDisplayName() + ") with a PatchAttachment");
+        try {
+            niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(),
new PatchAttachment(lRouterPort.getUuid()));
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid()
+ " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid()
+ " (" + lRouterPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying");
+            cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
+            cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName()
+ ") successfully attached to to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName()
+ ") with a PatchAttachment");
+
+        s_logger.info("Successfully attached Logical Switch " + logicalSwitchUuid + " on
Logical Router " + logicalRouterUuid + " for Shared Network " + networkId);
+        return new ConfigureSharedNetworkUuidAnswer(command, true, "OK");
+    }
+
+    private void cleanupLSwitchPort(String logicalSwitchUuid, LogicalSwitchPort lSwitchPort,
NiciraNvpApi niciraNvpApi) {
+        s_logger.warn("Deleting previously created Logical Switch Port " + lSwitchPort.getUuid()
+ " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid);
+        try {
+            niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lSwitchPort.getUuid());
+        } catch (NiciraNvpApiException exceptionDeleteLSwitchPort) {
+            s_logger.error("Error while deleting Logical Switch Port " + lSwitchPort.getUuid()
+ " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid + " due
to: " + exceptionDeleteLSwitchPort.getMessage());
+        }
+        s_logger.warn("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName()
+ ") successfully deleted");
+    }
+
+    private void cleanupLRouterPort(String logicalRouterUuid, LogicalRouterPort lRouterPort,
NiciraNvpApi niciraNvpApi) {
+        s_logger.warn("Deleting previously created Logical Router Port " + lRouterPort.getUuid()
+ " (" + lRouterPort.getDisplayName() + ") from Logical Router " + logicalRouterUuid + " and
retrying");
+        try {
+            niciraNvpApi.deleteLogicalRouterPort(logicalRouterUuid, lRouterPort.getUuid());
+        } catch (NiciraNvpApiException exceptionDelete) {
+            s_logger.error("Error while deleting Logical Router Port " + lRouterPort.getUuid()
+ " (" + lRouterPort.getDisplayName() + ") from Logical Router " + logicalRouterUuid + " due
to: " + exceptionDelete.getMessage());
+        }
+        s_logger.warn("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName()
+ ") successfully deleted");
+    }
+
+    private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkUuidCommand
command, NiciraNvpResource niciraNvpResource) {
+        if (HttpStatusCodeHelper.isConflict(e.getErrorCode())){
+            s_logger.warn("There's been a conflict in NSX side, aborting implementation");
+            return new ConfigureSharedNetworkUuidAnswer(command, false, "FAILED: There's
been a conflict in NSX side");
+        }
+        else {
+            s_logger.warn("Error code: " + e.getErrorCode() + ", retrying");
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, ConfigureSharedNetworkUuidAnswer.class, e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java
new file mode 100644
index 0000000..4fa9876
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java
@@ -0,0 +1,118 @@
+//
+// 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.NAME_MAX_LEN;
+import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer;
+import com.cloud.agent.api.ConfigureSharedNetworkVlanIdCommand;
+import com.cloud.network.nicira.L2GatewayAttachment;
+import com.cloud.network.nicira.LogicalSwitchPort;
+import com.cloud.network.nicira.NiciraNvpApi;
+import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.nicira.NiciraNvpTag;
+import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.utils.CommandRetryUtility;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+import com.cloud.utils.rest.HttpStatusCodeHelper;
+
+@ResourceWrapper(handles =  ConfigureSharedNetworkVlanIdCommand.class)
+public class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper extends CommandWrapper<ConfigureSharedNetworkVlanIdCommand,
Answer, NiciraNvpResource>{
+
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.class);
+
+    @Override
+    public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource
niciraNvpResource) {
+        final String logicalSwitchUuid = command.getLogicalSwitchUuid();
+        final String l2GatewayServiceUuid = command.getL2GatewayServiceUuid();
+        long vlanId = command.getVlanId();
+        final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
+        tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
+        final long networkId = command.getNetworkId();
+
+        s_logger.debug("Connecting Logical Switch " + logicalSwitchUuid + " to L2 Gateway
Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + " network " + networkId);
+        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
+
+        s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid);
+        LogicalSwitchPort lSwitchPort = null;
+        try {
+            lSwitchPort = new LogicalSwitchPort();
+            lSwitchPort.setAdminStatusEnabled(true);
+            lSwitchPort.setDisplayName(niciraNvpResource.truncate(networkId + "-l2Gateway-port",
NAME_MAX_LEN));
+            lSwitchPort.setTags(tags);
+            lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid
+ " due to: " + e.getMessage() + ", retrying");
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName()
+ ") successfully created in Logical Switch " + logicalSwitchUuid);
+
+        s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" +
lSwitchPort.getDisplayName() + ") on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
+        try {
+            final L2GatewayAttachment attachment = new L2GatewayAttachment(l2GatewayServiceUuid);
+            if (command.getVlanId() != 0) {
+                attachment.setVlanId(command.getVlanId());
+            }
+            niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(),
attachment);
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid()
+ " (" + lSwitchPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid()
+ " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", errorCode: " +
e.getErrorCode());
+            cleanup(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName()
+ ") successfully attached on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
+
+        s_logger.debug("Successfully connected Logical Switch " + logicalSwitchUuid + " to
L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + ", network " + networkId
+ ", through Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName()
+ ")");
+        return new ConfigureSharedNetworkVlanIdAnswer(command, true, "OK");
+    }
+
+    private void cleanup(String logicalSwitchUuid, LogicalSwitchPort lSwitchPort, NiciraNvpApi
niciraNvpApi) {
+        s_logger.warn("Deleting previously created Logical Switch Port " + lSwitchPort.getUuid()
+ " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid);
+        try {
+            niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lSwitchPort.getUuid());
+        } catch (NiciraNvpApiException exceptionDeleteLSwitchPort) {
+            s_logger.error("Error while deleting Logical Switch Port " + lSwitchPort.getUuid()
+ " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid + " due
to: " + exceptionDeleteLSwitchPort.getMessage());
+        }
+        s_logger.warn("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName()
+ ") successfully deteled");
+    }
+
+    private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkVlanIdCommand
command, NiciraNvpResource niciraNvpResource) {
+        if (HttpStatusCodeHelper.isConflict(e.getErrorCode())){
+            s_logger.warn("There's been a conflict in NSX side, aborting implementation");
+            return new ConfigureSharedNetworkVlanIdAnswer(command, false, "FAILED: There's
been a conflict in NSX side");
+        }
+        else {
+            s_logger.warn("Error code: " + e.getErrorCode() + ", retrying");
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, ConfigureSharedNetworkVlanIdAnswer.class,
e);
+        }
+    }
+
+}


Mime
View raw message