use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.
the class LabsdbService method syncWiremapData.
public void syncWiremapData(FacilitySoftwareConfig config, boolean isAll) {
wormholeApiClient.setServiceKey(serviceKeyConfig.getServiceKey());
List<Asset> servers = wormholeApiClient.getAllAssetsByType(AssetCategory.Server);
if (!isAll) {
servers = filterServers(servers);
}
Map<String, String> pduIDListMap = getAssetNameIDMap(AssetCategory.PDU);
Map<String, String> networkIDListMap = getAssetNameIDMap(AssetCategory.Networks);
LabsdbClient labsdbClient = createClient(config);
try {
if (!labsdbClient.checkConnection()) {
return;
}
} catch (HttpClientErrorException e) {
logger.error("Failed to query data from Labsdb", e);
IntegrationStatus integrationStatus = config.getIntegrationStatus();
if (integrationStatus == null) {
integrationStatus = new IntegrationStatus();
}
integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
integrationStatus.setDetail(e.getMessage());
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
updateIntegrationStatus(config);
return;
} catch (ResourceAccessException e1) {
if (e1.getCause().getCause() instanceof ConnectException) {
checkAndUpdateIntegrationStatus(config, e1.getMessage());
return;
}
}
// generatorWiremapData(servers,pduIDListMap,networkIDListMap,labsdbClient);
SAXParserFactory spf = SAXParserFactory.newInstance();
WiremapSaxHandler handler = new WiremapSaxHandler(wirmMap_node);
SAXParser parser = null;
try {
parser = spf.newSAXParser();
} catch (ParserConfigurationException | SAXException e) {
logger.error("Create new sax parser failed." + e.getMessage());
}
for (Asset asset : servers) {
ResponseEntity<String> resultEntity = null;
try {
resultEntity = labsdbClient.getWireMap(asset.getAssetName());
} catch (Exception e) {
logger.error("An exception occurred while accessing the labsdb server." + e.getMessage());
}
if (resultEntity == null || resultEntity.getBody() == null) {
continue;
}
try {
parser.parse(new ByteArrayInputStream(resultEntity.getBody().getBytes()), handler);
} catch (SAXException | IOException e) {
logger.error("Error parsing XML input stream.This XML input stream is " + resultEntity.getBody());
}
// Get all the devices connected to the server
List<EndDevice> devices = handler.getEndDevices();
if (devices == null || devices.isEmpty()) {
continue;
}
generatorWiremapData(asset, pduIDListMap, devices, networkIDListMap);
wormholeApiClient.saveAssets(asset);
}
}
use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.
the class FacilitySoftwareController method createServer.
// create a new facilitySoftwareConfig
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void createServer(@RequestBody FacilitySoftwareConfig config, HttpServletRequest request) {
HandleURL handleURL = new HandleURL();
config.setServerURL(handleURL.formatURL(config.getServerURL()));
if (repository.findOneByServerURL(config.getServerURL()) != null) {
String message = String.format("The server %s is already exsit.", config.getServerURL());
throw new WormholeRequestException(message);
}
serverValidationService.validateFacilityServer(config);
IntegrationStatus integrationStatus = new IntegrationStatus();
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
config.setIntegrationStatus(integrationStatus);
WormholeUserDetails user = accessTokenService.getCurrentUser(request);
config.setUserId(user.getUserId());
encryptServerPassword(config);
BaseDocumentUtil.generateID(config);
repository.save(config);
decryptServerPassword(config);
notifyFacilityWorker(config);
}
use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.
the class VCDataService method checkAndUpdateIntegrationStatus.
public void checkAndUpdateIntegrationStatus(SDDCSoftwareConfig vc, String message) {
IntegrationStatus integrationStatus = vc.getIntegrationStatus();
if (integrationStatus == null) {
integrationStatus = new IntegrationStatus();
}
int timesOftry = integrationStatus.getRetryCounter();
timesOftry++;
if (timesOftry < FlowgateConstant.MAXNUMBEROFRETRIES) {
integrationStatus.setRetryCounter(timesOftry);
} else {
integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
integrationStatus.setDetail(message);
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
logger.error("Failed to sync data to VC");
}
vc.setIntegrationStatus(integrationStatus);
updateIntegrationStatus(vc);
}
use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.
the class SDDCSoftwareControllerTest method createSDDCSoftwareConfig.
SDDCSoftwareConfig createSDDCSoftwareConfig(SoftwareType type) {
SDDCSoftwareConfig example = new SDDCSoftwareConfig();
example.setId(UUID.randomUUID().toString());
example.setName("test server");
example.setServerURL("10.160.30.134");
example.setType(type);
example.setUserName("administrator@vsphere.local");
example.setPassword("Admin!23");
example.setUserId("1001");
example.setVerifyCert(false);
example.setDescription("description");
IntegrationStatus integrationStatus = new IntegrationStatus();
example.setIntegrationStatus(integrationStatus);
return example;
}
use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.
the class InfoBloxService method executeAsync.
@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage eventMessage) {
// The data format of the message. should be an ip address.
// Do the business here.
String message = eventMessage.getContent();
logger.info(String.format("Try to find hostname for ip: %s", message));
// check message , make sure it is an valid ip address;
wormholeAPIClient.setServiceKey(serviceKeyConfig.getServiceKey());
FacilitySoftwareConfig[] infoBloxes = wormholeAPIClient.getFacilitySoftwareInternalByType(SoftwareType.InfoBlox).getBody();
List<InfoBloxIPInfoResult> infoBloxIPInfoResults = new ArrayList<>();
List<InfoBloxIPInfoResult> hostRecordResults = null;
List<InfoBloxIPInfoResult> ipv4addressResults = null;
for (FacilitySoftwareConfig infoblox : infoBloxes) {
if (!infoblox.checkIsActive()) {
continue;
}
InfobloxClient client = buildInfobloxClient(infoblox);
IntegrationStatus integrationStatus = infoblox.getIntegrationStatus();
IntegrationStatus.Status status = integrationStatus == null ? null : integrationStatus.getStatus();
try {
if (status == null || IntegrationStatus.Status.ACTIVE.equals(status)) {
hostRecordResults = client.queryHostRecordByIP(message);
logger.debug("queryHostRecordByIP: {}", hostRecordResults);
if (hostRecordResults != null && !hostRecordResults.isEmpty()) {
infoBloxIPInfoResults.addAll(hostRecordResults);
}
}
if (hostRecordResults == null || hostRecordResults.isEmpty()) {
ipv4addressResults = client.queryIpv4addressByIP(message);
logger.debug("queryHostNamesByIP: {}", ipv4addressResults);
if (ipv4addressResults != null && !ipv4addressResults.isEmpty()) {
infoBloxIPInfoResults.addAll(ipv4addressResults);
}
if (!IntegrationStatus.Status.WARNING.equals(status) && ipv4addressResults != null) {
updateIntegrationStatusToWarning(infoblox, message);
}
}
} catch (ResourceAccessException e) {
if (e.getCause().getCause() instanceof ConnectException) {
checkAndUpdateIntegrationStatus(infoblox, e.getCause().getCause().getMessage());
continue;
}
} catch (HttpClientErrorException e1) {
logger.error("Failed to query data from Infoblox", e1);
if (integrationStatus == null) {
integrationStatus = new IntegrationStatus();
}
integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
integrationStatus.setDetail(e1.getMessage());
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
infoblox.setIntegrationStatus(integrationStatus);
updateIntegrationStatus(infoblox);
continue;
}
if (integrationStatus != null && integrationStatus.getRetryCounter() > 0) {
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
updateIntegrationStatus(infoblox);
}
if (!infoBloxIPInfoResults.isEmpty()) {
for (InfoBloxIPInfoResult infoBloxIPInfoResult : infoBloxIPInfoResults) {
try {
Asset asset = wormholeAPIClient.getAssetByName(infoBloxIPInfoResult.getHostName()).getBody();
if (asset == null) {
logger.info(String.format("hostname (%s) no found!", infoBloxIPInfoResult.getHostName()));
continue;
}
} catch (HttpClientErrorException e) {
logger.error(String.format("Error when searching %s", infoBloxIPInfoResult.getHostName()), e);
continue;
}
AssetIPMapping tempMapping = new AssetIPMapping();
tempMapping.setAssetname(infoBloxIPInfoResult.getHostName());
tempMapping.setMacAddress(infoBloxIPInfoResult.getMacAddress());
tempMapping.setIp(message);
AssetIPMapping[] mappings = wormholeAPIClient.getHostnameIPMappingByIP(message).getBody();
boolean isNewMapping = true;
if (null != mappings && mappings.length > 0) {
for (AssetIPMapping mapping : mappings) {
if (tempMapping.getAssetname().equals(mapping.getAssetname())) {
if (!StringUtils.equals(mapping.getMacAddress(), tempMapping.getMacAddress())) {
mapping.setMacAddress(tempMapping.getMacAddress());
wormholeAPIClient.updateHostnameIPMapping(mapping);
}
isNewMapping = false;
break;
}
}
}
if (isNewMapping) {
wormholeAPIClient.createHostnameIPMapping(tempMapping);
}
logger.info(String.format("Find hostname %s for ip %s", infoBloxIPInfoResult.getHostName(), message));
return;
}
}
}
logger.info(String.format("Cannot find the hostname for IP: %s", message));
}
Aggregations