Search in sources :

Example 21 with Bridge

use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SendToBridgeActionTransformer method transform.

@Override
public BaseAction transform(BaseAction action, String bridgeId, String customerId, String processorId) {
    String destinationBridgeId = action.getParameters().getOrDefault(SendToBridgeAction.BRIDGE_ID_PARAM, bridgeId);
    Bridge destinationBridge = bridgesService.getReadyBridge(destinationBridgeId, customerId);
    Map<String, String> parameters = new HashMap<>();
    try {
        parameters.put(WebhookAction.ENDPOINT_PARAM, getBridgeWebhookUrl(destinationBridge.getEndpoint()));
        parameters.put(WebhookAction.USE_TECHNICAL_BEARER_TOKEN, "true");
    } catch (MalformedURLException e) {
        throw new ActionProviderException("Can't find events webhook for bridge " + destinationBridgeId);
    }
    BaseAction transformedAction = new BaseAction();
    transformedAction.setType(WebhookAction.TYPE);
    transformedAction.setParameters(parameters);
    return transformedAction;
}
Also used : MalformedURLException(java.net.MalformedURLException) ActionProviderException(com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException) HashMap(java.util.HashMap) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Bridge(com.redhat.service.bridge.manager.models.Bridge)

Example 22 with Bridge

use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SendToBridgeActionTransformerTest method beforeAll.

@BeforeAll
static void beforeAll() {
    bridge = new Bridge();
    bridge.setId(BRIDGE_ID);
    bridge.setName("bridge01");
    bridge.setCustomerId(TEST_CUSTOMER_ID);
    bridge.setStatus(ManagedResourceStatus.READY);
    bridge.setEndpoint(BRIDGE_ENDPOINT);
    otherBridge = new Bridge();
    otherBridge.setId(OTHER_BRIDGE_ID);
    otherBridge.setName("bridge02");
    otherBridge.setCustomerId(TEST_CUSTOMER_ID);
    otherBridge.setStatus(ManagedResourceStatus.READY);
    otherBridge.setEndpoint(OTHER_BRIDGE_ENDPOINT);
}
Also used : Bridge(com.redhat.service.bridge.manager.models.Bridge) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 23 with Bridge

use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeDAOTest method testFindByNameAndCustomerId.

@Test
public void testFindByNameAndCustomerId() {
    Bridge bridge = buildBridge(TestConstants.DEFAULT_BRIDGE_ID, TestConstants.DEFAULT_BRIDGE_NAME);
    bridgeDAO.persist(bridge);
    Bridge retrievedBridge = bridgeDAO.findByNameAndCustomerId("not-the-id", TestConstants.DEFAULT_CUSTOMER_ID);
    assertThat(retrievedBridge).isNull();
    retrievedBridge = bridgeDAO.findByNameAndCustomerId(TestConstants.DEFAULT_BRIDGE_NAME, "not-the-customer-id");
    assertThat(retrievedBridge).isNull();
    retrievedBridge = bridgeDAO.findByNameAndCustomerId(TestConstants.DEFAULT_BRIDGE_NAME, TestConstants.DEFAULT_CUSTOMER_ID);
    assertThat(retrievedBridge).isNotNull();
}
Also used : Bridge(com.redhat.service.bridge.manager.models.Bridge) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 24 with Bridge

use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeDAOTest method testListByCustomerId.

@Test
public void testListByCustomerId() {
    Bridge firstBridge = buildBridge(TestConstants.DEFAULT_BRIDGE_ID, TestConstants.DEFAULT_BRIDGE_NAME);
    bridgeDAO.persist(firstBridge);
    Bridge secondBridge = buildBridge("mySecondBridgeId", "mySecondBridgeName");
    bridgeDAO.persist(secondBridge);
    ListResult<Bridge> retrievedBridges = bridgeDAO.findByCustomerId(TestConstants.DEFAULT_CUSTOMER_ID, new QueryInfo(TestConstants.DEFAULT_PAGE, TestConstants.DEFAULT_PAGE_SIZE));
    assertThat(retrievedBridges).isNotNull();
    assertThat(retrievedBridges.getSize()).isEqualTo(2);
    assertThat(retrievedBridges.getTotal()).isEqualTo(2);
    assertThat(retrievedBridges.getPage()).isZero();
    // Newest istances come first
    assertThat(retrievedBridges.getItems().get(1).getId()).isEqualTo(firstBridge.getId());
    assertThat(retrievedBridges.getItems().get(0).getId()).isEqualTo(secondBridge.getId());
}
Also used : QueryInfo(com.redhat.service.bridge.infra.models.QueryInfo) Bridge(com.redhat.service.bridge.manager.models.Bridge) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 25 with Bridge

use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAOTest method findProcessorsToBeDeployedOrDelete.

@Test
@Transactional
public void findProcessorsToBeDeployedOrDelete() {
    Bridge b = createBridge();
    // To be provisioned
    Processor p = createProcessor(b, "foo");
    p.setDependencyStatus(ManagedResourceStatus.READY);
    processorDAO.getEntityManager().merge(p);
    // Already provisioned
    Processor q = createProcessor(b, "bob");
    q.setStatus(ManagedResourceStatus.READY);
    q.setDependencyStatus(ManagedResourceStatus.READY);
    processorDAO.getEntityManager().merge(q);
    // To be de-provisioned
    Processor r = createProcessor(b, "frank");
    r.setStatus(ManagedResourceStatus.DEPROVISION);
    r.setDependencyStatus(ManagedResourceStatus.DELETED);
    processorDAO.getEntityManager().merge(r);
    List<Processor> processors = processorDAO.findByShardIdWithReadyDependencies(TestConstants.SHARD_ID);
    assertThat(processors.size()).isEqualTo(2);
    processors.forEach((px) -> assertThat(px.getName()).isIn("foo", "frank"));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) Bridge(com.redhat.service.bridge.manager.models.Bridge) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Transactional(javax.transaction.Transactional)

Aggregations

Bridge (com.redhat.service.bridge.manager.models.Bridge)60 QuarkusTest (io.quarkus.test.junit.QuarkusTest)46 Test (org.junit.jupiter.api.Test)46 Processor (com.redhat.service.bridge.manager.models.Processor)34 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)15 QueryInfo (com.redhat.service.bridge.infra.models.QueryInfo)11 Transactional (javax.transaction.Transactional)8 BridgeRequest (com.redhat.service.bridge.manager.api.models.requests.BridgeRequest)7 ItemNotFoundException (com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException)6 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)6 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)6 Connector (com.openshift.cloud.api.connector.models.Connector)5 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)4 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)4 AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)3 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)3 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2 BridgeLifecycleException (com.redhat.service.bridge.infra.exceptions.definitions.user.BridgeLifecycleException)2 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)2 ZonedDateTime (java.time.ZonedDateTime)2