Search in sources :

Example 1 with SubscriptionStatusWithData

use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.

the class SubscriptionResource method refreshSubscription.

/**
 * Refresh given subscriptions and return their status.
 */
private SubscriptionStatusWithData refreshSubscription(final Subscription subscription) {
    final Map<String, String> parameters = getParameters(subscription.getId());
    final SubscriptionStatusWithData statusWithData = nodeResource.checkSubscriptionStatus(subscription, parameters);
    statusWithData.setId(subscription.getId());
    statusWithData.setProject(subscription.getProject().getId());
    statusWithData.setParameters(parameterValueResource.getNonSecuredSubscriptionParameters(subscription.getId()));
    // Update the last event with fresh data
    eventResource.registerEvent(subscription, EventType.STATUS, statusWithData.getStatus().name());
    // Return the fresh statuses
    return statusWithData;
}
Also used : SubscriptionStatusWithData(org.ligoj.app.api.SubscriptionStatusWithData)

Example 2 with SubscriptionStatusWithData

use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.

the class SubscriptionResourceTest method refreshStatuses.

@Test
public void refreshStatuses() throws IOException {
    persistEntities("csv", new Class[] { Event.class }, StandardCharsets.UTF_8.name());
    final int projectId = projectRepository.findByName("MDA").getId();
    final Map<Integer, EventVo> subscriptionStatus = resource.getStatusByProject(projectId);
    Assertions.assertEquals(1, subscriptionStatus.size());
    final Map<Integer, SubscriptionStatusWithData> statuses = resource.refreshStatuses(Collections.singleton(subscription));
    Assertions.assertEquals(1, statuses.size());
    final SubscriptionStatusWithData status = statuses.get(subscription);
    Assertions.assertEquals(subscription, status.getId().intValue());
    Assertions.assertEquals(NodeStatus.UP, status.getStatus());
    Assertions.assertEquals("service:bt:jira:4", status.getNode());
    Assertions.assertEquals(projectId, status.getProject().intValue());
    Assertions.assertNotNull(status.getParameters());
    Assertions.assertEquals(3, status.getParameters().size());
    Assertions.assertEquals("10074", status.getParameters().get("service:bt:jira:project"));
    Assertions.assertEquals("MDA", status.getParameters().get("service:bt:jira:pkey"));
    Assertions.assertEquals("http://localhost:8120", status.getParameters().get("service:bt:jira:url"));
}
Also used : SubscriptionStatusWithData(org.ligoj.app.api.SubscriptionStatusWithData) EventVo(org.ligoj.app.resource.node.EventVo) Test(org.junit.jupiter.api.Test) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest)

Example 3 with SubscriptionStatusWithData

use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.

the class NodeResourceTest method prepareSubscriptionsEvent.

private long prepareSubscriptionsEvent() throws Exception {
    // Check previous status
    final long eventsCount = eventRepository.count();
    Assertions.assertEquals(5, eventsCount);
    final ServicePluginLocator servicePluginLocator = resourceMock.locator;
    // Service is up --> SONAR
    final SonarPluginResource sonar = Mockito.mock(SonarPluginResource.class);
    Mockito.when(servicePluginLocator.getResource(ArgumentMatchers.anyString(), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(sonar);
    Mockito.when(servicePluginLocator.getResourceExpected(ArgumentMatchers.anyString(), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(sonar);
    Mockito.when(sonar.checkSubscriptionStatus(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString(), ArgumentMatchers.anyMap())).thenReturn(new SubscriptionStatusWithData());
    Mockito.when(sonar.checkStatus(ArgumentMatchers.anyString(), ArgumentMatchers.anyMap())).thenReturn(true);
    // Service is down --> JIRA
    final JiraPluginResource jira = Mockito.mock(JiraPluginResource.class);
    Mockito.when(servicePluginLocator.getResource(ArgumentMatchers.contains(":jira"), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(jira);
    Mockito.when(servicePluginLocator.getResourceExpected(ArgumentMatchers.contains(":jira"), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(jira);
    Mockito.when(jira.checkSubscriptionStatus(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString(), ArgumentMatchers.anyMap())).thenReturn(new SubscriptionStatusWithData(false));
    // Service throw an exception --> JENKINS
    final JenkinsPluginResource jenkins = Mockito.mock(JenkinsPluginResource.class);
    Mockito.when(servicePluginLocator.getResource(ArgumentMatchers.contains(":jenkins"), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(jenkins);
    Mockito.when(servicePluginLocator.getResourceExpected(ArgumentMatchers.contains(":jenkins"), ArgumentMatchers.eq(ToolPlugin.class))).thenReturn(jenkins);
    Mockito.when(jenkins.checkSubscriptionStatus(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString(), ArgumentMatchers.anyMap())).thenThrow(new TechnicalException("junit"));
    return eventsCount;
}
Also used : SubscriptionStatusWithData(org.ligoj.app.api.SubscriptionStatusWithData) TechnicalException(org.ligoj.bootstrap.core.resource.TechnicalException) JenkinsPluginResource(org.ligoj.app.resource.node.sample.JenkinsPluginResource) JiraPluginResource(org.ligoj.app.resource.node.sample.JiraPluginResource) SonarPluginResource(org.ligoj.app.resource.node.sample.SonarPluginResource) ServicePluginLocator(org.ligoj.app.resource.ServicePluginLocator) ToolPlugin(org.ligoj.app.api.ToolPlugin)

Example 4 with SubscriptionStatusWithData

use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.

the class AbstractToolPluginResource method checkSubscriptionStatus.

@Override
public SubscriptionStatusWithData checkSubscriptionStatus(final Map<String, String> parameters) {
    final SubscriptionStatusWithData status = new SubscriptionStatusWithData();
    status.put("property", "value");
    return status;
}
Also used : SubscriptionStatusWithData(org.ligoj.app.api.SubscriptionStatusWithData)

Example 5 with SubscriptionStatusWithData

use of org.ligoj.app.api.SubscriptionStatusWithData in project ligoj-api by ligoj.

the class SubscriptionResourceTest method checkSubscriptionStatus.

@Test
public void checkSubscriptionStatus() {
    JiraPluginResource service = servicePluginLocator.getResource("service:bt:jira:4", JiraPluginResource.class);
    final SubscriptionStatusWithData status = service.checkSubscriptionStatus(null);
    Assertions.assertNotNull(status);
    Assertions.assertEquals("value", status.getData().get("property"));
}
Also used : SubscriptionStatusWithData(org.ligoj.app.api.SubscriptionStatusWithData) JiraPluginResource(org.ligoj.app.resource.node.sample.JiraPluginResource) Test(org.junit.jupiter.api.Test) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest)

Aggregations

SubscriptionStatusWithData (org.ligoj.app.api.SubscriptionStatusWithData)7 Test (org.junit.jupiter.api.Test)2 ToolPlugin (org.ligoj.app.api.ToolPlugin)2 AbstractOrgTest (org.ligoj.app.resource.AbstractOrgTest)2 JiraPluginResource (org.ligoj.app.resource.node.sample.JiraPluginResource)2 ServicePluginLocator (org.ligoj.app.resource.ServicePluginLocator)1 EventVo (org.ligoj.app.resource.node.EventVo)1 JenkinsPluginResource (org.ligoj.app.resource.node.sample.JenkinsPluginResource)1 SonarPluginResource (org.ligoj.app.resource.node.sample.SonarPluginResource)1 BusinessException (org.ligoj.bootstrap.core.resource.BusinessException)1 TechnicalException (org.ligoj.bootstrap.core.resource.TechnicalException)1 ValidationJsonException (org.ligoj.bootstrap.core.validation.ValidationJsonException)1