Search in sources :

Example 16 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class GroupsStepDefinitions method there_should_be_groups_in_the_response.

@Then("^there should be (\\d+) groups in the response$")
public void there_should_be_groups_in_the_response(int expectedSize) throws Throwable {
    RestResponse<GetMultipleDataResult> restResponse = JsonUtil.read(Context.getInstance().takeRestResponse(), GetMultipleDataResult.class);
    GetMultipleDataResult searchResp = restResponse.getData();
    assertNotNull(searchResp);
    assertNotNull(searchResp.getTypes());
    assertNotNull(searchResp.getData());
    assertEquals(expectedSize, searchResp.getTypes().length);
    assertEquals(expectedSize, searchResp.getData().length);
}
Also used : GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Then(cucumber.api.java.en.Then)

Example 17 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class OrchestratorsDefinitionsSteps method Response_should_contains_an_orchestrator_with_name.

@Then("^Response should contains an orchestrator with name \"([^\"]*)\"$")
public void Response_should_contains_an_orchestrator_with_name(String name) throws Throwable {
    RestResponse<GetMultipleDataResult> response = JsonUtil.read(Context.getInstance().getRestResponse(), GetMultipleDataResult.class);
    boolean contains = false;
    for (Object cloudAsMap : response.getData().getData()) {
        Orchestrator orchestrator = JsonUtil.readObject(JsonUtil.toString(cloudAsMap), Orchestrator.class);
        if (name.equals(orchestrator.getName())) {
            contains = true;
        }
    }
    Assert.assertTrue(contains);
}
Also used : GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) Then(cucumber.api.java.en.Then)

Example 18 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class ServiceUsageReporter method reportServiceUsage.

@EventListener
private void reportServiceUsage(ServiceUsageRequestEvent serviceChangedEvent) {
    GetMultipleDataResult<Deployment> usageResult = alienDAO.buildQuery(Deployment.class).setFilters(fromKeyValueCouples("endDate", null, "serviceResourceIds", serviceChangedEvent.getServiceId())).prepareSearch().search(0, Integer.MAX_VALUE);
    if (usageResult.getTotalResults() > 0) {
        Usage[] usages = Arrays.stream(usageResult.getData()).map(deployment -> {
            ApplicationEnvironment environment = environmentService.getOrFail(deployment.getEnvironmentId());
            String usageName = "App (" + deployment.getSourceName() + "), Env (" + environment.getName() + ")";
            return new Usage(usageName, "Deployment", deployment.getId(), null);
        }).toArray(Usage[]::new);
        serviceChangedEvent.addUsages(usages);
    }
}
Also used : FilterUtil.fromKeyValueCouples(alien4cloud.dao.FilterUtil.fromKeyValueCouples) Arrays(java.util.Arrays) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Usage(alien4cloud.model.common.Usage) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) ServiceUsageRequestEvent(org.alien4cloud.alm.service.events.ServiceUsageRequestEvent) IGenericSearchDAO(alien4cloud.dao.IGenericSearchDAO) Inject(javax.inject.Inject) Deployment(alien4cloud.model.deployment.Deployment) Service(org.springframework.stereotype.Service) Usage(alien4cloud.model.common.Usage) Deployment(alien4cloud.model.deployment.Deployment) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) EventListener(org.springframework.context.event.EventListener)

Example 19 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class EsDaoSearchTest method simpleSearchTest.

@Test
public void simpleSearchTest() throws IndexingServiceException, InterruptedException, IOException {
    // test simple find all search
    GetMultipleDataResult searchResp = dao.find(NodeType.class, null, 10);
    assertNotNull(searchResp);
    assertEquals(4, searchResp.getTypes().length);
    assertEquals(4, searchResp.getData().length);
    // test simple find with filters
    Map<String, String[]> filters = new HashMap<String, String[]>();
    filters.put("capabilities.type", new String[] { "container" });
    searchResp = dao.find(NodeType.class, filters, 10);
    assertNotNull(searchResp);
    assertNotNull(searchResp.getTypes());
    assertNotNull(searchResp.getData());
    assertEquals(2, searchResp.getTypes().length);
    assertEquals(2, searchResp.getData().length);
}
Also used : HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Test(org.junit.Test)

Example 20 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class ApplicationVersionController method search.

/**
 * Search application versions for a given application id
 *
 * @param applicationId the targeted application id
 * @param searchRequest
 * @return A rest response that contains a {@link FacetedSearchResult} containing application versions for an application id sorted by version
 */
@ApiOperation(value = "Search application versions", notes = "Returns a search result with that contains application versions matching the request. A application version is returned only if the connected user has at least one application role in [ APPLICATION_MANAGER | APPLICATION_USER | APPLICATION_DEVOPS | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/search", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<GetMultipleDataResult<ApplicationVersion>> search(@PathVariable String applicationId, @RequestBody FilteredSearchRequest searchRequest) {
    Application application = applicationService.getOrFail(applicationId);
    AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.values());
    GetMultipleDataResult<ApplicationVersion> searchResult = appVersionService.search(applicationId, searchRequest.getQuery(), searchRequest.getFrom(), searchRequest.getSize());
    return RestResponseBuilder.<GetMultipleDataResult<ApplicationVersion>>builder().data(searchResult).build();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Application(alien4cloud.model.application.Application) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)32 Test (org.junit.Test)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ApiOperation (io.swagger.annotations.ApiOperation)7 HashMap (java.util.HashMap)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 Application (alien4cloud.model.application.Application)4 User (alien4cloud.security.model.User)4 Then (cucumber.api.java.en.Then)4 Location (alien4cloud.model.orchestrators.locations.Location)3 IdsFilterBuilder (org.elasticsearch.index.query.IdsFilterBuilder)3 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)2 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 FilteredSearchRequest (alien4cloud.rest.model.FilteredSearchRequest)2 Group (alien4cloud.security.model.Group)2 Arrays (java.util.Arrays)2 Resource (javax.annotation.Resource)2