use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class SDDCSoftwareController method getServerConfigsByUser.
// get servers by user and type
@RequestMapping(value = "/type/{type}", method = RequestMethod.GET)
public List<SDDCSoftwareConfig> getServerConfigsByUser(@PathVariable("type") SoftwareType type, HttpServletRequest request) {
WormholeUserDetails user = accessTokenService.getCurrentUser(request);
List<SDDCSoftwareConfig> datas = sddcRepository.findAllByUserIdAndType(user.getUserId(), type.name());
for (SDDCSoftwareConfig sddcSoftwareConfig : datas) {
sddcSoftwareConfig.setPassword(null);
}
return datas;
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class SDDCSoftwareController method notifySDDCWorker.
private void notifySDDCWorker(SDDCSoftwareConfig server) {
String jobList = null;
String jobTarget1 = null;
String jobTarget2 = null;
String notifyTopic = null;
EventType eventType = null;
switch(server.getType()) {
case VCENTER:
jobList = EventMessageUtil.vcJobList;
jobTarget1 = EventMessageUtil.VCENTER_SyncCustomerAttrs;
jobTarget2 = EventMessageUtil.VCENTER_SyncCustomerAttrsData;
notifyTopic = EventMessageUtil.VCTopic;
eventType = EventType.VCenter;
break;
case VRO:
jobList = EventMessageUtil.vroJobList;
jobTarget1 = EventMessageUtil.VRO_SyncMetricPropertyAndAlert;
jobTarget2 = EventMessageUtil.VRO_SyncMetricData;
notifyTopic = EventMessageUtil.VROTopic;
eventType = EventType.VROps;
break;
default:
return;
}
try {
logger.info(String.format("Notify %s worker to start sync data, job queue:%s, notifytopic:%s", server.getType(), jobList, notifyTopic));
template.opsForList().leftPushAll(jobList, EventMessageUtil.generateSDDCMessageListByType(eventType, jobTarget1, new SDDCSoftwareConfig[] { server }));
template.opsForList().leftPushAll(jobList, EventMessageUtil.generateSDDCMessageListByType(eventType, jobTarget2, new SDDCSoftwareConfig[] { server }));
publisher.publish(notifyTopic, EventMessageUtil.generateSDDCNotifyMessage(eventType));
} catch (IOException e) {
logger.error("Failed to send out message", e);
}
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class SDDCSoftwareController method queryServer.
@RequestMapping(value = "/page/{pageNumber}/pagesize/{pageSize}", method = RequestMethod.GET)
public Page<SDDCSoftwareConfig> queryServer(@PathVariable("pageNumber") int currentPage, @PathVariable("pageSize") int pageSize, HttpServletRequest request) {
if (currentPage < FlowgateConstant.defaultPageNumber) {
currentPage = FlowgateConstant.defaultPageNumber;
} else if (pageSize <= 0) {
pageSize = FlowgateConstant.defaultPageSize;
} else if (pageSize > FlowgateConstant.maxPageSize) {
pageSize = FlowgateConstant.maxPageSize;
}
PageRequest pageRequest = PageRequest.of(currentPage - 1, pageSize);
WormholeUserDetails user = accessTokenService.getCurrentUser(request);
try {
Page<SDDCSoftwareConfig> result = sddcRepository.findAllByUserId(user.getUserId(), pageRequest);
for (SDDCSoftwareConfig sddcSoftwareConfig : result.getContent()) {
sddcSoftwareConfig.setPassword(null);
}
return result;
} catch (Exception e) {
throw new WormholeRequestException(e.getMessage());
}
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class AggregatorService method mergeServerMapping.
public void mergeServerMapping() {
// first get all vc
// second get all vros
// merge the data
// TODO improve the efficiency of compare?
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
SDDCSoftwareConfig[] vcs = restClient.getInternalSDDCSoftwareConfigByType(SDDCSoftwareConfig.SoftwareType.VCENTER).getBody();
SDDCSoftwareConfig[] vrops = restClient.getInternalSDDCSoftwareConfigByType(SDDCSoftwareConfig.SoftwareType.VRO).getBody();
Map<String, ServerMapping> vroMapping = new HashMap<String, ServerMapping>();
for (SDDCSoftwareConfig vro : vrops) {
ServerMapping[] mappings = restClient.getServerMappingsByVRO(vro.getId()).getBody();
for (ServerMapping mapping : mappings) {
vroMapping.put(mapping.getVroVMEntityVCID() + ":" + mapping.getVroVMEntityObjectID(), mapping);
}
}
for (SDDCSoftwareConfig vc : vcs) {
ServerMapping[] mappings = restClient.getServerMappingsByVC(vc.getId()).getBody();
for (ServerMapping mapping : mappings) {
String key = mapping.getVcInstanceUUID() + ":" + mapping.getVcMobID();
if (vroMapping.containsKey(key)) {
// check if they are same item.
ServerMapping vroMap = vroMapping.get(key);
if (!mapping.getId().equals(vroMap.getId())) {
// need to merge the mapping.
if (vroMap.getAsset() != null) {
restClient.mergMapping(vroMap.getId(), mapping.getId());
} else {
// if (mapping.getAssetID() != null) we should allow to merge unmapped mapping items.
restClient.mergMapping(mapping.getId(), vroMap.getId());
}
}
}
}
}
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class VCDataServiceTest method testSyncCustomerAttrsData.
@Test
public void testSyncCustomerAttrsData() throws Exception {
String assetId = "QONVN1098G1NVN01NG01";
String vcMobID = "host-11";
SDDCSoftwareConfig sddcSoftwareConfig = new SDDCSoftwareConfig();
sddcSoftwareConfig.setType(SDDCSoftwareConfig.SoftwareType.VCENTER);
sddcSoftwareConfig.setServerURL("https://1.1.1.1");
sddcSoftwareConfig.setPassword("ASDFGAGAHAHwegqhwrjw");
sddcSoftwareConfig.setVerifyCert(false);
EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.VCenter, EventMessageUtil.VCENTER_SyncCustomerAttrsData, mapper.writeValueAsString(sddcSoftwareConfig));
ListOperations<String, String> listOperations = Mockito.mock(ListOperations.class);
doReturn(listOperations).when(template).opsForList();
doReturn(mapper.writeValueAsString(eventMessage), null).when(listOperations).rightPop(EventMessageUtil.vcJobList);
doReturn(vsphereClient).when(service).connectVsphere(any());
ServerMapping serverMapping = new ServerMapping();
serverMapping.setVcMobID(vcMobID);
serverMapping.setVcHostName("server-1");
serverMapping.setAsset(assetId);
ServerMapping[] serverMappings = { serverMapping };
doReturn(new ResponseEntity<>(serverMappings, HttpStatus.OK)).when(restClient).getServerMappingsByVC(any());
Collection<HostSystem> hostSystems = new ArrayList<>();
HostSystem hostSystem = mock(HostSystem.class);
ManagedObjectReference managedObjectReference = mock(ManagedObjectReference.class);
hostSystems.add(hostSystem);
doReturn(managedObjectReference).when(hostSystem)._getRef();
doReturn("server-1").when(hostSystem).getName();
doReturn(vcMobID).when(managedObjectReference).getValue();
doReturn(hostSystems).when(vsphereClient).getAllHost();
Asset asset = new Asset();
asset.setId(assetId);
Map<String, String> metricsFormulas = new HashMap<>();
Map<String, String> hostMetricsFormula = new HashMap<>();
hostMetricsFormula.put(MetricName.SERVER_TEMPERATURE, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_PEAK_TEMPERATURE, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_AVERAGE_TEMPERATURE, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_ENERGY_CONSUMPTION, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_POWER, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_AVERAGE_USED_POWER, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_PEAK_USED_POWER, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_MINIMUM_USED_POWER, asset.getId());
metricsFormulas.put(FlowgateConstant.HOST_METRICS, asset.metricsFormulaToString(hostMetricsFormula));
asset.setMetricsformulars(metricsFormulas);
Asset[] assets = { asset };
doReturn(new ResponseEntity<>(assets, HttpStatus.OK)).when(restClient).getAssetsByVCID(any());
doReturn(new ResponseEntity<Void>(HttpStatus.OK)).when(restClient).saveAssets(any(Asset.class));
service.executeAsync(EventMessageUtil.createEventMessage(EventType.VCenter, EventMessageUtil.VCENTER_SyncData, null));
}
Aggregations