Search in sources :

Example 36 with FacilitySoftwareConfig

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

the class FacilitySoftwareController method getFacilitySoftwareConfigByID.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public FacilitySoftwareConfig getFacilitySoftwareConfigByID(@PathVariable String id) {
    Optional<FacilitySoftwareConfig> serverOptional = repository.findById(id);
    FacilitySoftwareConfig server = serverOptional.get();
    server.setPassword(null);
    return server;
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with FacilitySoftwareConfig

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

the class FacilitySoftwareController method updateStatus.

// only modify the status of integration,and not verify information of server.
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/status", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateStatus(@RequestBody FacilitySoftwareConfig server) {
    Optional<FacilitySoftwareConfig> oldServerOptional = repository.findById(server.getId());
    if (!oldServerOptional.isPresent()) {
        throw WormholeRequestException.NotFound("FacilitySoftwareConfig", "id", server.getId());
    }
    FacilitySoftwareConfig old = oldServerOptional.get();
    old.setIntegrationStatus(server.getIntegrationStatus());
    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 38 with FacilitySoftwareConfig

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

the class CustomerAdapterJobDispatcher method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    Map<String, FacilityAdapter> facilityAdapterMap = initFacilityAdapterMap();
    if (facilityAdapterMap.isEmpty()) {
        return;
    }
    List<FacilitySoftwareConfig> facilityIntegrations = getIntegrations();
    if (facilityIntegrations.isEmpty()) {
        return;
    }
    String execountString = template.opsForValue().get(EventMessageUtil.CUSTOMER_ADAPTER_EXECOUNT);
    if (execountString == null || "".equals(execountString)) {
        execountString = "0";
    }
    long execount = Long.valueOf(execountString);
    execount++;
    template.opsForValue().set(EventMessageUtil.CUSTOMER_ADAPTER_EXECOUNT, String.valueOf(execount));
    for (FacilitySoftwareConfig integration : facilityIntegrations) {
        String subcategory = integration.getSubCategory();
        FacilityAdapter adapter = facilityAdapterMap.get(subcategory);
        sendMessage(execount, integration, adapter);
    }
    logger.info("Send customer adapter job finished");
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter)

Example 39 with FacilitySoftwareConfig

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

the class CustomerAdapterJobDispatcher method sendMessage.

private void sendMessage(long execount, FacilitySoftwareConfig integration, FacilityAdapter adapter) {
    String topic = adapter.getTopic();
    String queue = adapter.getQueueName();
    List<AdapterJobCommand> commands = adapter.getCommands();
    for (AdapterJobCommand command : commands) {
        int executeCycle = command.getTriggerCycle() / EVERY_CYCLE;
        if (execount % executeCycle == 0) {
            try {
                template.opsForList().leftPushAll(queue, EventMessageUtil.generateFacilityMessageListByType(null, command.getCommand(), new FacilitySoftwareConfig[] { integration }));
                EventMessage message = EventMessageUtil.createEventMessage(null, null, NODIFY_MESSAGE);
                publisher.publish(topic, EventMessageUtil.convertEventMessageAsString(message));
                logger.info("Send " + command.getCommand() + " of " + integration.getName() + " success");
            } catch (IOException e) {
                logger.error("Failed to send out message", e);
            }
        }
    }
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

Example 40 with FacilitySoftwareConfig

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

the class AdapterJobService method executeAsync.

@Override
public void executeAsync(EventMessage message) {
    // TODO Auto-generated method stub
    logger.info("message received");
    String messageString = null;
    while ((messageString = template.opsForList().rightPop(queueName)) != 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 integration = null;
        try {
            integration = mapper.readValue(payloadMessage.getContent(), FacilitySoftwareConfig.class);
        } catch (IOException e) {
            logger.error("Cannot process message", e);
        }
        if (null == integration) {
            continue;
        }
        if (!integration.checkIsActive()) {
            continue;
        }
        for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
            excuteJob(payloadCommand.getId(), integration);
        }
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventMessageImpl(com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl) EventUser(com.vmware.flowgate.common.model.redis.message.EventUser) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

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