Skip to content

Commit b4ce81a

Browse files
CLOUDSTACK-8590 - Refactoring NiciraNVP resource
- Adding NiciraNvpDeleteLogicalSwitchPortCommandWrapper Signed-off-by: wilderrodrigues <wrodrigues@schubergphilis.com>
1 parent 361ab5d commit b4ce81a

5 files changed

Lines changed: 58 additions & 15 deletions

File tree

plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpRequestWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// specific language governing permissions and limitations
1717
// under the License.
1818
//
19+
1920
package com.cloud.network.resource;
2021

2122
import java.util.Hashtable;

plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import com.cloud.agent.api.CreateLogicalRouterCommand;
4141
import com.cloud.agent.api.DeleteLogicalRouterAnswer;
4242
import com.cloud.agent.api.DeleteLogicalRouterCommand;
43-
import com.cloud.agent.api.DeleteLogicalSwitchPortAnswer;
44-
import com.cloud.agent.api.DeleteLogicalSwitchPortCommand;
4543
import com.cloud.agent.api.FindLogicalSwitchPortAnswer;
4644
import com.cloud.agent.api.FindLogicalSwitchPortCommand;
4745
import com.cloud.agent.api.PingCommand;
@@ -207,9 +205,7 @@ public Answer executeRequest(final Command cmd) {
207205
// [TODO] Remove when all the commands are refactored.
208206
}
209207

210-
if (cmd instanceof DeleteLogicalSwitchPortCommand) {
211-
return executeRequest((DeleteLogicalSwitchPortCommand)cmd, NUM_RETRIES);
212-
} else if (cmd instanceof UpdateLogicalSwitchPortCommand) {
208+
if (cmd instanceof UpdateLogicalSwitchPortCommand) {
213209
return executeRequest((UpdateLogicalSwitchPortCommand)cmd, NUM_RETRIES);
214210
} else if (cmd instanceof FindLogicalSwitchPortCommand) {
215211
return executeRequest((FindLogicalSwitchPortCommand)cmd, NUM_RETRIES);
@@ -241,16 +237,6 @@ public IAgentControl getAgentControl() {
241237
public void setAgentControl(final IAgentControl agentControl) {
242238
}
243239

244-
private Answer executeRequest(final DeleteLogicalSwitchPortCommand cmd, final int numRetries) {
245-
try {
246-
niciraNvpApi.deleteLogicalSwitchPort(cmd.getLogicalSwitchUuid(), cmd.getLogicalSwitchPortUuid());
247-
return new DeleteLogicalSwitchPortAnswer(cmd, true, "Logical switch port " + cmd.getLogicalSwitchPortUuid() + " deleted");
248-
} catch (final NiciraNvpApiException e) {
249-
retryUtility.addRetry(cmd, NUM_RETRIES);
250-
return retryUtility.retry(cmd, DeleteLogicalSwitchPortAnswer.class, e);
251-
}
252-
}
253-
254240
private Answer executeRequest(final UpdateLogicalSwitchPortCommand cmd, final int numRetries) {
255241
final String logicalSwitchUuid = cmd.getLogicalSwitchUuid();
256242
final String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid();

plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// specific language governing permissions and limitations
1717
// under the License.
1818
//
19+
1920
package com.cloud.network.resource;
2021

2122
import java.util.ArrayList;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.resource.wrapper;
21+
22+
import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
23+
24+
import org.apache.log4j.Logger;
25+
26+
import com.cloud.agent.api.Answer;
27+
import com.cloud.agent.api.DeleteLogicalSwitchPortAnswer;
28+
import com.cloud.agent.api.DeleteLogicalSwitchPortCommand;
29+
import com.cloud.network.nicira.NiciraNvpApi;
30+
import com.cloud.network.nicira.NiciraNvpApiException;
31+
import com.cloud.network.resource.NiciraNvpResource;
32+
import com.cloud.network.utils.CommandRetryUtility;
33+
import com.cloud.resource.CommandWrapper;
34+
import com.cloud.resource.ResourceWrapper;
35+
36+
@ResourceWrapper(handles = DeleteLogicalSwitchPortCommand.class)
37+
public final class NiciraNvpDeleteLogicalSwitchPortCommandWrapper extends CommandWrapper<DeleteLogicalSwitchPortCommand, Answer, NiciraNvpResource> {
38+
39+
private static final Logger s_logger = Logger.getLogger(NiciraNvpDeleteLogicalSwitchPortCommandWrapper.class);
40+
41+
@Override
42+
public Answer execute(final DeleteLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) {
43+
final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
44+
45+
try {
46+
niciraNvpApi.deleteLogicalSwitchPort(command.getLogicalSwitchUuid(), command.getLogicalSwitchPortUuid());
47+
return new DeleteLogicalSwitchPortAnswer(command, true, "Logical switch port " + command.getLogicalSwitchPortUuid() + " deleted");
48+
} catch (final NiciraNvpApiException e) {
49+
final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
50+
retryUtility.addRetry(command, NUM_RETRIES);
51+
return retryUtility.retry(command, DeleteLogicalSwitchPortAnswer.class, e);
52+
}
53+
}
54+
}

plugins/network-elements/nicira-nvp/src/com/cloud/network/utils/CommandRetryUtility.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// specific language governing permissions and limitations
1717
// under the License.
1818
//
19+
1920
package com.cloud.network.utils;
2021

2122
import java.lang.reflect.Constructor;

0 commit comments

Comments
 (0)