Search in sources :

Example 26 with SDDCSoftwareConfig

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;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with SDDCSoftwareConfig

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);
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) EventType(com.vmware.flowgate.common.model.redis.message.EventType) IOException(java.io.IOException)

Example 28 with SDDCSoftwareConfig

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());
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) PageRequest(org.springframework.data.domain.PageRequest) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchElementException(java.util.NoSuchElementException) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) IOException(java.io.IOException) WormholeException(com.vmware.flowgate.common.exception.WormholeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with SDDCSoftwareConfig

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());
                    }
                }
            }
        }
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) HashMap(java.util.HashMap) ServerMapping(com.vmware.flowgate.common.model.ServerMapping)

Example 30 with SDDCSoftwareConfig

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));
}
Also used : HashMap(java.util.HashMap) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) HostSystem(com.vmware.vim.binding.vim.HostSystem) Asset(com.vmware.flowgate.common.model.Asset) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference) Test(org.junit.Test)

Aggregations

SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)42 Test (org.junit.Test)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)11 ArrayList (java.util.ArrayList)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 SoftwareType (com.vmware.flowgate.common.model.SDDCSoftwareConfig.SoftwareType)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Asset (com.vmware.flowgate.common.model.Asset)6 IOException (java.io.IOException)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 AuthVcUser (com.vmware.flowgate.auth.AuthVcUser)5 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)5 HashMap (java.util.HashMap)5 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)5 HostSystem (com.vmware.vim.binding.vim.HostSystem)4 ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)4