Skip to content

Commit fc47860

Browse files
CLOUDSTACK-8590 - Refactoring NiciraNVP resource
- Adding the NiciraNvpWrapper - This class will keep track of all Wrappers of the Nicira NVP Plugin Signed-off-by: wilderrodrigues <[email protected]>
1 parent 9463356 commit fc47860

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 com.cloud.network.resource;
20+
21+
import java.util.Hashtable;
22+
import java.util.Set;
23+
24+
import org.reflections.Reflections;
25+
26+
import com.cloud.agent.api.Answer;
27+
import com.cloud.agent.api.Command;
28+
import com.cloud.resource.CommandWrapper;
29+
import com.cloud.resource.RequestWrapper;
30+
import com.cloud.resource.ServerResource;
31+
32+
public class NiciraNvpRequestWrapper extends RequestWrapper {
33+
34+
private static NiciraNvpRequestWrapper instance;
35+
36+
static {
37+
instance = new NiciraNvpRequestWrapper();
38+
}
39+
40+
Reflections baseWrappers = new Reflections("com.cloud.network.resource.wrapper");
41+
@SuppressWarnings("rawtypes")
42+
Set<Class<? extends CommandWrapper>> baseSet = baseWrappers.getSubTypesOf(CommandWrapper.class);
43+
44+
private NiciraNvpRequestWrapper() {
45+
init();
46+
}
47+
48+
@SuppressWarnings("rawtypes")
49+
private void init() {
50+
// NiciraNvpResource commands
51+
final Hashtable<Class<? extends Command>, CommandWrapper> libvirtCommands = processAnnotations(baseSet);
52+
53+
resources.put(NiciraNvpResource.class, libvirtCommands);
54+
}
55+
56+
public static NiciraNvpRequestWrapper getInstance() {
57+
return instance;
58+
}
59+
60+
@SuppressWarnings({"rawtypes" })
61+
@Override
62+
public Answer execute(final Command command, final ServerResource serverResource) {
63+
final Class<? extends ServerResource> resourceClass = serverResource.getClass();
64+
65+
final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands = retrieveResource(command, resourceClass);
66+
67+
CommandWrapper<Command, Answer, ServerResource> commandWrapper = retrieveCommands(command.getClass(), resourceCommands);
68+
69+
while (commandWrapper == null) {
70+
//Could not find the command in the given resource, will traverse the family tree.
71+
commandWrapper = retryWhenAllFails(command, resourceClass, resourceCommands);
72+
}
73+
74+
return commandWrapper.execute(command, serverResource);
75+
}
76+
}

0 commit comments

Comments
 (0)