Skip to content

Commit a659409

Browse files
author
Sigert Goeminne
committed
Performance improvement: caching of NuageVsp ID
1 parent f1c01a5 commit a659409

File tree

17 files changed

+585
-36
lines changed

17 files changed

+585
-36
lines changed

plugins/network-elements/nuage-vsp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</repository>
3636
</repositories>
3737
<properties>
38-
<nuage.vsp.client.version>1.0.1</nuage.vsp.client.version>
38+
<nuage.vsp.client.version>1.0.3</nuage.vsp.client.version>
3939
</properties>
4040
<dependencies>
4141
<dependency>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.manager;
21+
22+
import net.nuage.vsp.acs.client.api.model.NetworkRelatedVsdIds;
23+
24+
import com.cloud.agent.api.Answer;
25+
import com.cloud.agent.api.guru.ImplementNetworkVspCommand;
26+
27+
/**
28+
* Created by sgoeminn on 3/24/17.
29+
*/
30+
public class ImplementNetworkVspAnswer extends Answer {
31+
private NetworkRelatedVsdIds networkRelatedVsdIds;
32+
33+
public ImplementNetworkVspAnswer(ImplementNetworkVspCommand command, NetworkRelatedVsdIds networkRelatedVsdIds) {
34+
super(command);
35+
this.networkRelatedVsdIds = networkRelatedVsdIds;
36+
}
37+
38+
public ImplementNetworkVspAnswer(ImplementNetworkVspCommand command, Exception e) {
39+
super(command, e);
40+
}
41+
42+
public NetworkRelatedVsdIds getNetworkRelatedVsdIds() {
43+
return networkRelatedVsdIds;
44+
}
45+
}

plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import javax.inject.Inject;
2727

28+
import net.nuage.vsp.acs.client.api.model.NetworkRelatedVsdIds;
2829
import org.apache.cloudstack.resourcedetail.VpcDetailVO;
2930
import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao;
3031
import org.apache.log4j.Logger;
@@ -36,6 +37,7 @@
3637
import com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand;
3738
import com.cloud.agent.api.guru.TrashNetworkVspCommand;
3839
import com.cloud.agent.api.guru.UpdateDhcpOptionVspCommand;
40+
import com.cloud.agent.api.manager.ImplementNetworkVspAnswer;
3941
import com.cloud.configuration.ConfigurationManager;
4042
import com.cloud.dc.DataCenter;
4143
import com.cloud.dc.DataCenter.NetworkType;
@@ -206,7 +208,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
206208
implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
207209
implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
208210

209-
if (!implement(physicalNetworkId, vspNetwork, _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering))) {
211+
if (!implement(network.getVpcId(), physicalNetworkId, vspNetwork, _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering))) {
210212
return null;
211213
}
212214

@@ -227,20 +229,65 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
227229
return implemented;
228230
}
229231

230-
private boolean implement(long physicalNetworkId, VspNetwork vspNetwork, VspDhcpDomainOption vspDhcpDomainOption) {
232+
private boolean implement(Long vpcId, long physicalNetworkId, VspNetwork vspNetwork, VspDhcpDomainOption vspDhcpDomainOption) {
231233
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(physicalNetworkId);
232234
ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(vspNetwork, vspDhcpDomainOption);
233-
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
235+
ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer) _agentMgr.easySend(nuageVspHost.getId(), cmd);
234236
if (answer == null || !answer.getResult()) {
235237
s_logger.error("ImplementNetworkVspCommand for network " + vspNetwork.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
236238
if ((null != answer) && (null != answer.getDetails())) {
237239
s_logger.error(answer.getDetails());
238240
}
239241
return false;
240242
}
243+
saveNetworkAndVpcDetails(vspNetwork, answer.getNetworkRelatedVsdIds(), vpcId);
241244
return true;
242245
}
243246

247+
private void saveNetworkAndVpcDetails(VspNetwork vspNetwork, NetworkRelatedVsdIds networkRelatedVsdIds, Long vpcId) {
248+
249+
250+
if (!vspNetwork.isShared() && !vspNetwork.getNetworkRelatedVsdIds().equals(networkRelatedVsdIds)) {
251+
Map<String, String> networkDetails = constructNetworkDetails(networkRelatedVsdIds, vspNetwork.isVpc());
252+
253+
for (Map.Entry<String, String> networkDetail : networkDetails.entrySet()) {
254+
NetworkDetailVO networkDetailVO = new NetworkDetailVO(vspNetwork.getId(), networkDetail.getKey(), networkDetail.getValue(), false);
255+
_networkDetailsDao.persist(networkDetailVO);
256+
}
257+
258+
if(vspNetwork.isVpc()) {
259+
Map<String, String> vpcDetails = constructVpcDetails(networkRelatedVsdIds);
260+
261+
for (Map.Entry<String, String> vpcDetail : vpcDetails.entrySet()) {
262+
VpcDetailVO vpcDetailVO = new VpcDetailVO(vpcId, vpcDetail.getKey(), vpcDetail.getValue(), false);
263+
_vpcDetailsDao.persist(vpcDetailVO);
264+
}
265+
}
266+
}
267+
}
268+
269+
private static Map<String, String> constructNetworkDetails(NetworkRelatedVsdIds networkRelatedVsdIds, boolean isVpc) {
270+
Map<String, String> networkDetails = Maps.newHashMap();
271+
272+
if(!isVpc) {
273+
networkRelatedVsdIds.getVsdDomainId().ifPresent(v -> networkDetails.put(NuageVspManager.NETWORK_METADATA_VSD_DOMAIN_ID, v));
274+
networkRelatedVsdIds.getVsdZoneId().ifPresent(v -> networkDetails.put(NuageVspManager.NETWORK_METADATA_VSD_ZONE_ID, v));
275+
}
276+
networkRelatedVsdIds.getVsdSubnetId().ifPresent(v -> networkDetails.put(NuageVspManager.NETWORK_METADATA_VSD_SUBNET_ID, v));
277+
278+
return networkDetails;
279+
}
280+
281+
private static Map<String, String> constructVpcDetails(NetworkRelatedVsdIds networkRelatedVsdIds) {
282+
Map<String, String> vpcDetails = Maps.newHashMap();
283+
284+
networkRelatedVsdIds.getVsdDomainId().ifPresent(v -> vpcDetails.put(NuageVspManager.NETWORK_METADATA_VSD_DOMAIN_ID, v));
285+
networkRelatedVsdIds.getVsdZoneId().ifPresent(v -> vpcDetails.put(NuageVspManager.NETWORK_METADATA_VSD_ZONE_ID, v));
286+
287+
return vpcDetails;
288+
}
289+
290+
244291
@Override
245292
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
246293
if (vm.getType() != VirtualMachine.Type.DomainRouter && _nuageVspEntityBuilder.usesVirtualRouter(network.getNetworkOfferingId())) {
@@ -303,7 +350,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D
303350

304351
// Make sure the shared network is present
305352
NetworkOffering offering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
306-
if (!implement(network.getPhysicalNetworkId(), vspNetwork, _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering))) {
353+
if (!implement(network.getVpcId(), network.getPhysicalNetworkId(), vspNetwork, _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering))) {
307354
s_logger.error("Failed to implement shared network " + network.getUuid() + " under domain " + context.getDomain().getUuid());
308355
throw new InsufficientVirtualNetworkCapacityException("Failed to implement shared network " + network.getUuid() + " under domain " +
309356
context.getDomain().getUuid(), Network.class, network.getId());

plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManager.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@
3636

3737
public interface NuageVspManager extends PluggableService {
3838

39-
static final String nuageVspSharedNetworkOfferingWithSGServiceName = "DefaultNuageVspSharedNetworkOfferingWithSGService";
39+
String nuageVspSharedNetworkOfferingWithSGServiceName = "DefaultNuageVspSharedNetworkOfferingWithSGService";
4040

41-
static final String nuageVPCOfferingName = "Nuage VSP VPC Offering";
41+
String nuageVPCOfferingName = "Nuage VSP VPC Offering";
4242

43-
static final String nuageVPCOfferingDisplayText = "Nuage VSP VPC Offering";
43+
String nuageVPCOfferingDisplayText = "Nuage VSP VPC Offering";
4444

45-
static final String nuageDomainTemplateDetailName = "domainTemplateName";
45+
String nuageDomainTemplateDetailName = "domainTemplateName";
4646

47-
static final String nuageUnderlayVlanIpRangeDetailKey = "nuage.underlay";
47+
String nuageUnderlayVlanIpRangeDetailKey = "nuage.underlay";
4848

49-
static final ConfigKey<Boolean> NuageVspConfigDns = new ConfigKey<Boolean>(Boolean.class, "nuagevsp.configure.dns", "Advanced", "true",
49+
ConfigKey<Boolean> NuageVspConfigDns = new ConfigKey<Boolean>(Boolean.class, "nuagevsp.configure.dns", "Advanced", "true",
5050
"Defines if NuageVsp plugin needs to configure DNS setting for a VM or not. True will configure the DNS and false will not configure the DNS settings", true,
5151
Scope.Global, null);
5252

53-
static final ConfigKey<Boolean> NuageVspDnsExternal = new ConfigKey<Boolean>(
53+
ConfigKey<Boolean> NuageVspDnsExternal = new ConfigKey<Boolean>(
5454
Boolean.class,
5555
"nuagevsp.dns.external",
5656
"Advanced",
@@ -61,18 +61,24 @@ public interface NuageVspManager extends PluggableService {
6161
+ "If nuagevsp.configure.dns is false, DNS server will not be configured in the VM. Default value for this flag is true",
6262
true, Scope.Global, null);
6363

64-
static final ConfigKey<String> NuageVspConfigGateway = new ConfigKey<String>(String.class, "nuagevsp.configure.gateway.systemid", "Advanced", "",
64+
ConfigKey<String> NuageVspConfigGateway = new ConfigKey<String>(String.class, "nuagevsp.configure.gateway.systemid", "Advanced", "",
6565
"Defines the systemID of the gateway configured in VSP", true, Scope.Global, null);
6666

67-
static final ConfigKey<String> NuageVspSharedNetworkDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.sharedntwk.domaintemplate.name",
67+
ConfigKey<String> NuageVspSharedNetworkDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.sharedntwk.domaintemplate.name",
6868
"Advanced", "", "Defines if NuageVsp plugin needs to use pre created Domain Template configured in VSP for shared networks", true, Scope.Global, null);
6969

70-
static final ConfigKey<String> NuageVspVpcDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.vpc.domaintemplate.name",
70+
ConfigKey<String> NuageVspVpcDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.vpc.domaintemplate.name",
7171
"Advanced", "", "Defines if NuageVsp plugin needs to use pre created Domain Template configured in VSP for VPCs", true, Scope.Global, null);
7272

73-
static final ConfigKey<String> NuageVspIsolatedNetworkDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.isolatedntwk.domaintemplate.name",
73+
ConfigKey<String> NuageVspIsolatedNetworkDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.isolatedntwk.domaintemplate.name",
7474
"Advanced", "", "Defines if NuageVsp plugin needs to use pre created Domain Template configured in VSP for isolated networks", true, Scope.Global, null);
7575

76+
String NETWORK_METADATA_VSD_DOMAIN_ID = "vsdDomainId";
77+
78+
String NETWORK_METADATA_VSD_ZONE_ID = "vsdZoneId";
79+
80+
String NETWORK_METADATA_VSD_SUBNET_ID = "vsdSubnetId";
81+
7682
NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd);
7783

7884
NuageVspDeviceVO updateNuageVspDevice(UpdateNuageVspDeviceCmd cmd);

plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Map;
2929
import java.util.Set;
3030
import java.util.UUID;
31-
import java.util.concurrent.ExecutionException;
3231

3332
import javax.inject.Inject;
3433
import javax.naming.ConfigurationException;
@@ -41,6 +40,7 @@
4140
import net.nuage.vsp.acs.client.common.NuageVspApiVersion;
4241
import net.nuage.vsp.acs.client.common.NuageVspConstants;
4342

43+
import net.nuage.vsp.acs.client.exception.NuageVspException;
4444
import org.apache.commons.collections.CollectionUtils;
4545
import org.apache.commons.lang3.StringUtils;
4646
import org.apache.log4j.Logger;
@@ -365,7 +365,7 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
365365
} catch (ConfigurationException e) {
366366
s_logger.error("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
367367
throw new CloudRuntimeException("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
368-
} catch (ExecutionException ee) {
368+
} catch (NuageVspException ee) {
369369
s_logger.error("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
370370
throw new CloudRuntimeException("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
371371
}

plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
package com.cloud.network.resource;
2121

2222
import java.util.Map;
23-
import java.util.concurrent.ExecutionException;
23+
import java.util.concurrent.atomic.AtomicLong;
24+
import java.util.stream.Collectors;
2425

2526
import javax.naming.ConfigurationException;
2627

@@ -31,6 +32,8 @@
3132
import net.nuage.vsp.acs.client.api.NuageVspManagerClient;
3233
import net.nuage.vsp.acs.client.api.NuageVspPluginClientLoader;
3334
import net.nuage.vsp.acs.client.api.model.VspHost;
35+
import net.nuage.vsp.acs.client.common.RequestType;
36+
import net.nuage.vsp.acs.client.common.model.NuageVspEntity;
3437
import net.nuage.vsp.acs.client.exception.NuageVspException;
3538

3639
import org.apache.log4j.Logger;
@@ -48,8 +51,9 @@
4851
import com.cloud.resource.ServerResource;
4952
import com.cloud.utils.component.ManagerBase;
5053
import com.cloud.utils.exception.CloudRuntimeException;
54+
import com.cloud.utils.mgmt.JmxUtil;
5155

52-
public class NuageVspResource extends ManagerBase implements ServerResource {
56+
public class NuageVspResource extends ManagerBase implements ServerResource, VspStatisticsMBean {
5357
private static final Logger s_logger = Logger.getLogger(NuageVspResource.class);
5458

5559
private String _guid;
@@ -87,14 +91,72 @@ public VspHost validate(NuageVspResourceConfiguration configuration) throws Conf
8791

8892
_vspHost = newVspHost;
8993
_clientLoader = clientLoader;
90-
} catch (ExecutionException e) {
94+
} catch (NuageVspException e) {
9195
s_logger.error(e.getMessage(), e);
9296
throw new CloudRuntimeException(e.getMessage(), e);
9397
}
9498

9599
return _vspHost;
96100
}
97101

102+
@Override
103+
public long getVSDStatistics() {
104+
return _clientLoader.getNuageVspStatistics().getVsdCount();
105+
}
106+
107+
108+
@Override
109+
public long getVsdStatisticsByEntityType(String entity) {
110+
try {
111+
NuageVspEntity nuageVspEntity = NuageVspEntity.valueOf(entity);
112+
return _clientLoader.getNuageVspStatistics().getVsdCount(nuageVspEntity);
113+
} catch (IllegalArgumentException e) {
114+
return -1;
115+
}
116+
}
117+
118+
@Override
119+
public long getVsdStatisticsByRequestType(String requestType) {
120+
try {
121+
RequestType requestTypeValue = RequestType.valueOf(requestType);
122+
return _clientLoader.getNuageVspStatistics().getVsdCount(requestTypeValue);
123+
} catch (IllegalArgumentException e) {
124+
return -1;
125+
}
126+
127+
}
128+
129+
@Override
130+
public long getVsdStatisticsByEntityAndRequestType(String entity, String requestType) {
131+
try {
132+
RequestType requestTypeValue = RequestType.valueOf(requestType);
133+
NuageVspEntity nuageVspEntity = NuageVspEntity.valueOf(entity);
134+
return _clientLoader.getNuageVspStatistics().getVsdCount(nuageVspEntity, requestTypeValue);
135+
} catch (IllegalArgumentException e) {
136+
return -1;
137+
}
138+
}
139+
140+
private static Map<String, AtomicLong> convertHashMap(Map<RequestType, AtomicLong> map) {
141+
return map.entrySet()
142+
.stream()
143+
.collect(Collectors.toMap(
144+
e -> e.getKey().toString(),
145+
Map.Entry::getValue)
146+
);
147+
}
148+
149+
@Override
150+
public Map<String, Map<String, AtomicLong>> getVsdStatisticsReport() {
151+
return _clientLoader.getNuageVspStatistics()
152+
.getVsdCountReport()
153+
.entrySet().stream()
154+
.collect(Collectors.toMap(
155+
e -> e.getKey().toString(),
156+
e -> convertHashMap(e.getValue())
157+
));
158+
}
159+
98160
@Override
99161
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
100162
if(super.configure(name, params)) {
@@ -113,11 +175,25 @@ protected NuageVspPluginClientLoader getClientLoader(VspHost vspHost) {
113175

114176
@Override
115177
public boolean start() {
178+
try {
179+
JmxUtil.registerMBean("NuageVspResource", _name, new VspStatisticsMBeanImpl(this));
180+
} catch (Exception e) {
181+
s_logger.warn("Unable to initialize statistics Mbean", e);
182+
}
183+
116184
return true;
185+
117186
}
118187

119188
@Override
120189
public boolean stop() {
190+
191+
try {
192+
JmxUtil.unregisterMBean("NuageVspResource", _name);
193+
} catch (Exception e) {
194+
s_logger.warn("Unable to initialize inaccurate clock", e);
195+
}
196+
121197
return true;
122198
}
123199

@@ -155,7 +231,7 @@ public PingCommand getCurrentStatus(long id) {
155231

156232
try {
157233
login();
158-
} catch (ExecutionException | ConfigurationException e) {
234+
} catch (NuageVspException | ConfigurationException e) {
159235
s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " +_vspHost.getCmsUserLogin(), e);
160236
_shouldAudit = true;
161237
return null;

0 commit comments

Comments
 (0)