Search in sources :

Example 16 with SDDCSoftwareConfig

use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.

the class VCDataServiceTest method testQueryHostMetaData.

@Test
public void testQueryHostMetaData() throws Exception {
    SDDCSoftwareConfig vc = Mockito.mock(SDDCSoftwareConfig.class);
    HashMap<String, ServerMapping> serverMappingMap = new HashMap<String, ServerMapping>();
    ServerMapping mapping1 = new ServerMapping();
    mapping1.setVcMobID("vc1");
    mapping1.setAsset("asset1");
    serverMappingMap.put(mapping1.getVcMobID(), mapping1);
    ServerMapping mapping2 = new ServerMapping();
    mapping2.setVcMobID("vc2");
    mapping2.setAsset("asset2");
    serverMappingMap.put(mapping2.getVcMobID(), mapping2);
    doReturn(serverMappingMap).when(service).getVaildServerMapping(any());
    doReturn(vsphereClient).when(service).connectVsphere(any());
    HostSystem host1 = Mockito.mock(HostSystem.class);
    HostSystem host2 = Mockito.mock(HostSystem.class);
    Collection<HostSystem> hosts = new ArrayList<>();
    hosts.add(host1);
    hosts.add(host2);
    when(vsphereClient.getAllHost()).thenReturn(hosts);
    Collection<ClusterComputeResource> clusterComputeResources = new ArrayList<>();
    ClusterComputeResource cluster = Mockito.mock(ClusterComputeResource.class);
    clusterComputeResources.add(cluster);
    clusterComputeResources.add(cluster);
    when(vsphereClient.getAllClusterComputeResource()).thenReturn(clusterComputeResources);
    ManagedObjectReference mor1 = Mockito.mock(ManagedObjectReference.class);
    ManagedObjectReference mor2 = Mockito.mock(ManagedObjectReference.class);
    when(host1._getRef()).thenReturn(mor1);
    when(mor1.getValue()).thenReturn("vc1");
    when(host2._getRef()).thenReturn(mor2);
    when(mor2.getValue()).thenReturn("vc2");
    Asset asset = new Asset();
    asset.setId("asset1");
    HashMap<String, String> hostJustification = new HashMap<String, String>();
    HostInfo hostInfo = new HostInfo();
    String vcHostObjStr = mapper.writeValueAsString(hostInfo);
    hostJustification.put(FlowgateConstant.HOST_METADATA, vcHostObjStr);
    asset.setJustificationfields(hostJustification);
    ResponseEntity<Asset> assets = Mockito.mock(ResponseEntity.class);
    when(restClient.getAssetByID(anyString())).thenReturn(assets);
    when(assets.getBody()).thenReturn(asset);
    doReturn(true).when(service).feedHostMetaData(any(), any());
    doReturn(true).when(service).feedClusterMetaData(any(), any(), any(), anyString());
    service.queryHostMetaData(vc);
}
Also used : ClusterComputeResource(com.vmware.vim.binding.vim.ClusterComputeResource) 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) HostSystem(com.vmware.vim.binding.vim.HostSystem) Asset(com.vmware.flowgate.common.model.Asset) HostInfo(com.vmware.flowgate.vcworker.model.HostInfo) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference) Test(org.junit.Test)

Example 17 with SDDCSoftwareConfig

use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.

the class VROAsyncJob method executeAsync.

@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage message) {
    if (message.getType() != EventType.VROps) {
        logger.warn("Drop none VROps message " + message.getType());
        return;
    }
    // TO, this should be comment out since it may contain vc password.
    logger.info("message received");
    Set<EventUser> users = message.getTarget().getUsers();
    for (EventUser command : users) {
        logger.info(command.getId());
        switch(command.getId()) {
            case EventMessageUtil.VRO_SyncData:
                String messageString = null;
                while ((messageString = template.opsForList().rightPop(EventMessageUtil.vroJobList)) != null) {
                    EventMessage payloadMessage = null;
                    try {
                        payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (payloadMessage == null) {
                        continue;
                    }
                    SDDCSoftwareConfig vroInfo = null;
                    try {
                        vroInfo = mapper.readValue(payloadMessage.getContent(), SDDCSoftwareConfig.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (null == vroInfo) {
                        continue;
                    }
                    for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
                        switch(payloadCommand.getId()) {
                            case EventMessageUtil.VRO_SyncMetricData:
                                syncVROMetricData(vroInfo);
                                logger.info("Finish Sync Metric data for " + vroInfo.getName());
                                break;
                            case EventMessageUtil.VRO_SyncMetricPropertyAndAlert:
                                syncVROMetricPropertyAlertDefinition(vroInfo);
                                logger.info("Finish Sync customer attributes and alerts for " + vroInfo.getName());
                                break;
                            default:
                                break;
                        }
                    }
                }
                break;
            case EventMessageUtil.VRO_SyncMetricData:
                logger.warn("VRO_SyncMetricData command is deprecated, please use VRO_SyncData");
                break;
            case EventMessageUtil.VRO_SyncMetricPropertyAndAlert:
                logger.warn("VRO_SyncMetricPropertyAndAlert command is deprecated, please use VRO_SyncData");
                break;
            default:
                logger.warn("Unknown command, ignore it: " + command.getId());
                break;
        }
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventUser(com.vmware.flowgate.common.model.redis.message.EventUser) EventMessageImpl(com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl) IOException(java.io.IOException) Async(org.springframework.scheduling.annotation.Async)

Example 18 with SDDCSoftwareConfig

use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.

the class SummaryService method getVroSummaryList.

public List<VroSummary> getVroSummaryList() {
    List<VroSummary> vroSummary = new ArrayList<>();
    List<SDDCSoftwareConfig> sddcSoftwareConfigs = sddcrpeo.findAllByType(SoftwareType.VRO.name());
    for (SDDCSoftwareConfig s : sddcSoftwareConfigs) {
        VroSummary vro = new VroSummary();
        vro.setName(s.getName());
        vro.setUrl(s.getServerURL());
        vro.setHostsNum(summaryRepository.countServerMappingByVRO(s.getId()));
        vroSummary.add(vro);
    }
    return vroSummary;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) VroSummary(com.vmware.flowgate.common.model.VroSummary) ArrayList(java.util.ArrayList)

Example 19 with SDDCSoftwareConfig

use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.

the class SDDCSoftwareController method syncSDDCServerData.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/syncdatabyserverid/{id}", method = RequestMethod.POST)
public void syncSDDCServerData(@PathVariable("id") String id, HttpServletRequest request) {
    Optional<SDDCSoftwareConfig> sddcOptional = sddcRepository.findById(id);
    SDDCSoftwareConfig server = sddcOptional.get();
    String userID = getCurrentUserID(request);
    if (!userID.equals(server.getUserId())) {
        return;
    }
    decryptServerPassword(server);
    notifySDDCWorker(server);
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with SDDCSoftwareConfig

use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.

the class VCenterJobDispatcher method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    // Read all the vcenter information, send to the redis topic
    // this job will be triggered every 5 minutes.
    // every 5 minutes we will trigger a sync host realtimedata job.
    // every 12 hour we will trigger a sync host metadata job.
    // every 1 day we will trigger a sync CustomerAttrsData job.
    // every 10 days we will trigger a sync CustomAttributes job.
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    SDDCSoftwareConfig[] vcServers = restClient.getInternalSDDCSoftwareConfigByType(SDDCSoftwareConfig.SoftwareType.VCENTER).getBody();
    if (vcServers == null || vcServers.length == 0) {
        logger.info("No vcenter server find");
        return;
    }
    List<SDDCSoftwareConfig> serverActiveList = new ArrayList<SDDCSoftwareConfig>();
    for (SDDCSoftwareConfig vc : vcServers) {
        if (vc.checkIsActive()) {
            serverActiveList.add(vc);
        }
    }
    if (serverActiveList.size() == 0) {
        return;
    }
    SDDCSoftwareConfig[] vcServersActiveArray = (SDDCSoftwareConfig[]) serverActiveList.toArray(new SDDCSoftwareConfig[serverActiveList.size()]);
    String execountString = template.opsForValue().get(EventMessageUtil.VCENTER_EXECOUNT);
    if (execountString == null || "".equals(execountString)) {
        execountString = "0";
    }
    long execount = Long.valueOf(execountString);
    boolean queryHostMetadata = execount % 144 == 0;
    boolean syncCustomerAttrsData = execount % 288 == 0;
    boolean syncCustomAttributes = execount % 2880 == 0;
    execount++;
    try {
        template.opsForValue().set(EventMessageUtil.VCENTER_EXECOUNT, String.valueOf(execount));
    } catch (Exception e) {
        logger.error("Failed to set execount", e);
    }
    try {
        logger.info("Send query Host usage data commands");
        template.opsForList().leftPushAll(EventMessageUtil.vcJobList, generateSDDCMessageListByType(EventMessageUtil.VCENTER_QueryHostUsageData, vcServersActiveArray));
        if (queryHostMetadata) {
            logger.info("Send query Host meta data commands");
            template.opsForList().leftPushAll(EventMessageUtil.vcJobList, generateSDDCMessageListByType(EventMessageUtil.VCENTER_QueryHostMetaData, vcServersActiveArray));
        }
        if (syncCustomerAttrsData) {
            logger.info("Send Sync VC customer attributes data commands");
            template.opsForList().leftPushAll(EventMessageUtil.vcJobList, generateSDDCMessageListByType(EventMessageUtil.VCENTER_SyncCustomerAttrsData, vcServersActiveArray));
        }
        if (syncCustomAttributes) {
            logger.info("Send Sync VC customer attributes commands");
            template.opsForList().leftPushAll(EventMessageUtil.vcJobList, generateSDDCMessageListByType(EventMessageUtil.VCENTER_SyncCustomerAttrs, vcServersActiveArray));
        }
        publisher.publish(EventMessageUtil.VCTopic, EventMessageUtil.generateSDDCNotifyMessage(EventType.VCenter));
    } catch (IOException e) {
        logger.error("Failed to send out message", e);
    }
    logger.info("Sync VC findished");
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JobExecutionException(org.quartz.JobExecutionException)

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