Search in sources :

Example 1 with CmProfile

use of com.sequenceiq.mock.clouderamanager.CmProfile in project cloudbreak by hortonworks.

the class ConfigureController method configure.

@GetMapping("/{mockUuid}/profile/{profile}/{times}")
public void configure(@PathVariable("mockUuid") String mockUuid, @PathVariable("profile") String profile, @PathVariable("times") int times) {
    if (!clouderaManagerStoreService.exists(mockUuid)) {
        clouderaManagerStoreService.start(mockUuid);
    }
    List<CmProfile> activeProfiles = clouderaManagerStoreService.read(mockUuid).getActiveProfiles();
    Optional<CmProfile> cmProfileOpt = activeProfiles.stream().filter(p -> p.getProfile().equals(profile)).findFirst();
    if (cmProfileOpt.isPresent()) {
        CmProfile cmProfile = cmProfileOpt.get();
        if (times == 0) {
            activeProfiles.remove(cmProfile);
        } else {
            cmProfile.setTimes(times);
        }
    } else {
        activeProfiles.add(new CmProfile(profile, times));
    }
}
Also used : Inject(javax.inject.Inject) RequestBody(org.springframework.web.bind.annotation.RequestBody) PathVariable(org.springframework.web.bind.annotation.PathVariable) PostMapping(org.springframework.web.bind.annotation.PostMapping) List(java.util.List) ResponseModifierService(com.sequenceiq.mock.service.ResponseModifierService) CmProfile(com.sequenceiq.mock.clouderamanager.CmProfile) ClouderaManagerStoreService(com.sequenceiq.mock.clouderamanager.ClouderaManagerStoreService) Optional(java.util.Optional) GetMapping(org.springframework.web.bind.annotation.GetMapping) MockResponse(com.sequenceiq.mock.spi.MockResponse) RestController(org.springframework.web.bind.annotation.RestController) CmProfile(com.sequenceiq.mock.clouderamanager.CmProfile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with CmProfile

use of com.sequenceiq.mock.clouderamanager.CmProfile in project cloudbreak by hortonworks.

the class ResponseModifierService method handleProfiles.

public void handleProfiles(String mockUuid, String path) {
    if (mockUuid != null && profileSupported(mockUuid, path) && clouderaManagerStoreService.exists(mockUuid)) {
        ClouderaManagerDto dto = clouderaManagerStoreService.read(mockUuid);
        Optional<CmProfile> http500 = dto.getActiveProfiles().stream().filter(p -> p.getProfile().equals("HTTP_500")).findFirst();
        if (http500.isPresent()) {
            int called = profileCalled.computeIfAbsent(path, key -> 0);
            profileCalled.put(path, called + 1);
            if (called < http500.get().getTimes()) {
                throw new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "HTTP_500 profile set");
            }
        }
    }
}
Also used : Logger(org.slf4j.Logger) CmProfile(com.sequenceiq.mock.clouderamanager.CmProfile) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) ClouderaManagerStoreService(com.sequenceiq.mock.clouderamanager.ClouderaManagerStoreService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) MockResponse(com.sequenceiq.mock.spi.MockResponse) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CheckedSupplier(com.sequenceiq.cloudbreak.util.CheckedSupplier) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ClouderaManagerDto(com.sequenceiq.mock.clouderamanager.ClouderaManagerDto) Service(org.springframework.stereotype.Service) CollectionUtils(org.springframework.util.CollectionUtils) Gson(com.google.gson.Gson) Map(java.util.Map) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) ClouderaManagerDto(com.sequenceiq.mock.clouderamanager.ClouderaManagerDto) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) CmProfile(com.sequenceiq.mock.clouderamanager.CmProfile)

Aggregations

ClouderaManagerStoreService (com.sequenceiq.mock.clouderamanager.ClouderaManagerStoreService)2 CmProfile (com.sequenceiq.mock.clouderamanager.CmProfile)2 MockResponse (com.sequenceiq.mock.spi.MockResponse)2 List (java.util.List)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 Gson (com.google.gson.Gson)1 CheckedSupplier (com.sequenceiq.cloudbreak.util.CheckedSupplier)1 ClouderaManagerDto (com.sequenceiq.mock.clouderamanager.ClouderaManagerDto)1 ResponseModifierService (com.sequenceiq.mock.service.ResponseModifierService)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 HttpStatus (org.springframework.http.HttpStatus)1 ResponseEntity (org.springframework.http.ResponseEntity)1 Service (org.springframework.stereotype.Service)1 CollectionUtils (org.springframework.util.CollectionUtils)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1