Search in sources :

Example 31 with FacilitySoftwareConfig

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

the class InfobloxClientTest method getInfobloxFacilitySoftware.

private FacilitySoftwareConfig[] getInfobloxFacilitySoftware() {
    FacilitySoftwareConfig[] facilitySoftwareConfigs = new FacilitySoftwareConfig[1];
    FacilitySoftwareConfig facilitySoftwareConfig = new FacilitySoftwareConfig();
    facilitySoftwareConfig.setPassword("O75xginpkAD748w=Lc20CrTzd1lEpvDTdJqH5IXBZTb5gYp7P8awDAs19F0=");
    facilitySoftwareConfig.setServerURL("https://10.161.71.133");
    facilitySoftwareConfig.setName("infoblox-1");
    facilitySoftwareConfig.setVerifyCert(false);
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setRetryCounter(0);
    integrationStatus.setDetail("");
    integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
    facilitySoftwareConfig.setIntegrationStatus(integrationStatus);
    facilitySoftwareConfig.setUserName("admin");
    facilitySoftwareConfig.setType(FacilitySoftwareConfig.SoftwareType.InfoBlox);
    facilitySoftwareConfig.setUserId("e1edfv8953002379827896a1aaiqoose");
    facilitySoftwareConfigs[0] = facilitySoftwareConfig;
    return facilitySoftwareConfigs;
}
Also used : IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig)

Example 32 with FacilitySoftwareConfig

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

the class LabsdbService method executeAsync.

@Override
public void executeAsync(EventMessage message) {
    // TODO Auto-generated method stub
    if (message.getType() != EventType.Labsdb) {
        logger.warn("Drop none Labsdb message " + message.getType());
        return;
    }
    logger.info("message received");
    Set<EventUser> users = message.getTarget().getUsers();
    for (EventUser command : users) {
        logger.info(command.getId());
        switch(command.getId()) {
            case EventMessageUtil.Labsdb_SyncData:
                // it will sync all the data depend on the type in the labsdbJobList.
                String messageString = null;
                while ((messageString = template.opsForList().rightPop(EventMessageUtil.labsdbJobList)) != null) {
                    EventMessage payloadMessage = null;
                    try {
                        payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (payloadMessage == null) {
                        continue;
                    }
                    FacilitySoftwareConfig labsdb = null;
                    try {
                        labsdb = mapper.readValue(payloadMessage.getContent(), FacilitySoftwareConfig.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (null == labsdb) {
                        continue;
                    }
                    if (!labsdb.checkIsActive()) {
                        continue;
                    }
                    for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
                        excuteJob(payloadCommand.getId(), labsdb);
                    }
                }
                break;
            default:
                FacilitySoftwareConfig labsdb = null;
                try {
                    labsdb = mapper.readValue(message.getContent(), FacilitySoftwareConfig.class);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    logger.error("Failed to convert message", e1);
                }
                if (labsdb != null) {
                    excuteJob(command.getId(), labsdb);
                }
                break;
        }
    }
}
Also used : 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) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

Example 33 with FacilitySoftwareConfig

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

the class AssetController method searchAssetsByAssetNameAndTagLike.

// searchAssetsByAssetNameAndTagLike
@RequestMapping(value = { "/page/{pageNumber}/pagesize/{pageSize}/keywords/{keyWords}", "/page/{pageNumber}/pagesize/{pageSize}" }, method = RequestMethod.GET)
public Page<Asset> searchAssetsByAssetNameAndTagLike(@PathVariable("pageNumber") int pageNumber, @PathVariable("pageSize") int pageSize, @PathVariable(required = false) String keyWords, @RequestParam(required = false) AssetCategory category) {
    if (keyWords == null) {
        keyWords = "%%";
    } else {
        keyWords = "%" + keyWords + "%";
    }
    if (category == null) {
        category = AssetCategory.Server;
    }
    if (pageNumber < FlowgateConstant.defaultPageNumber) {
        pageNumber = FlowgateConstant.defaultPageNumber;
    } else if (pageSize <= 0) {
        pageSize = FlowgateConstant.defaultPageSize;
    } else if (pageSize > FlowgateConstant.maxPageSize) {
        pageSize = FlowgateConstant.maxPageSize;
    }
    PageRequest pageable = PageRequest.of(pageNumber - 1, pageSize);
    List<Asset> assets = assetRepository.findByAssetNameLikeAndCategory(keyWords, category.name(), pageSize, pageSize * (pageNumber - 1));
    PageImpl<Asset> assetPage = new PageImpl<Asset>(assets, pageable, 0);
    HashMap<String, String> assetSourceIDAndAssetSourceNameMap = new HashMap<String, String>();
    assetSourceIDAndAssetSourceNameMap.put(FLOWGATE_SOURCE, FLOWGATE_SOURCE);
    for (Asset asset : assetPage.getContent()) {
        String assetSourceID = asset.getAssetSource();
        if (assetSourceID == null) {
            continue;
        }
        String[] assetSource = assetSourceID.split(FlowgateConstant.SPILIT_FLAG);
        List<String> assetSourceNames = new ArrayList<String>();
        for (String sourceId : assetSource) {
            String assetSourceName = assetSourceIDAndAssetSourceNameMap.get(sourceId);
            if (assetSourceName == null) {
                Optional<FacilitySoftwareConfig> facilityOptional = facilityRepository.findById(sourceId);
                if (facilityOptional.isPresent()) {
                    assetSourceName = facilityOptional.get().getName();
                    assetSourceIDAndAssetSourceNameMap.put(sourceId, assetSourceName);
                }
            }
            assetSourceNames.add(assetSourceName);
        }
        String sourceNames = String.join(FlowgateConstant.SPILIT_FLAG, assetSourceNames);
        asset.setAssetSource(sourceNames);
    }
    return assetPage;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PageRequest(org.springframework.data.domain.PageRequest) Asset(com.vmware.flowgate.common.model.Asset) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with FacilitySoftwareConfig

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

the class FacilitySoftwareController method updateFacilitySoftwareConfig.

// Update
@ResponseStatus(HttpStatus.OK)
@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateFacilitySoftwareConfig(@RequestBody FacilitySoftwareConfig config) {
    Optional<FacilitySoftwareConfig> oldServerOptional = repository.findById(config.getId());
    if (!oldServerOptional.isPresent()) {
        throw WormholeRequestException.NotFound("FacilitySoftwareConfig", "id", config.getId());
    }
    FacilitySoftwareConfig old = oldServerOptional.get();
    old.setName(config.getName());
    old.setDescription(config.getDescription());
    old.setUserName(config.getUserName());
    old.setVerifyCert(config.isVerifyCert());
    old.setAdvanceSetting(config.getAdvanceSetting());
    old.setIntegrationStatus(config.getIntegrationStatus());
    if (StringUtils.isNotBlank(config.getPassword())) {
        old.setPassword(config.getPassword());
    } else {
        decryptServerPassword(old);
    }
    serverValidationService.validateFacilityServer(old);
    encryptServerPassword(old);
    repository.save(old);
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with FacilitySoftwareConfig

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

the class FacilitySoftwareController method syncFacilityServerData.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/syncdatabyserverid/{id}", method = RequestMethod.POST)
public void syncFacilityServerData(@PathVariable("id") String id, HttpServletRequest request) {
    Optional<FacilitySoftwareConfig> serverOptional = repository.findById(id);
    if (!serverOptional.isPresent()) {
        throw WormholeRequestException.NotFound("FacilitySoftwareConfig", "id", id);
    }
    FacilitySoftwareConfig server = serverOptional.get();
    decryptServerPassword(server);
    notifyFacilityWorker(server);
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)60 Test (org.junit.Test)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)29 ArrayList (java.util.ArrayList)13 Asset (com.vmware.flowgate.common.model.Asset)8 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)7 IOException (java.io.IOException)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)6 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)5 EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)5 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)5 HashMap (java.util.HashMap)5 ResponseEntity (org.springframework.http.ResponseEntity)5 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)4 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)4 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)4