Skip to content
Snippets Groups Projects

Resolve "Create missing service classes"

2 files
+ 143
4
Compare changes
  • Side-by-side
  • Inline
Files
2
package cz.muni.ics.kypo.training.adaptive.service.api;
import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingRun;
import cz.muni.ics.kypo.training.adaptive.dto.responses.LockedPoolInfo;
import cz.muni.ics.kypo.training.adaptive.dto.responses.PoolInfoDTO;
import cz.muni.ics.kypo.training.adaptive.dto.responses.SandboxDefinitionInfo;
import cz.muni.ics.kypo.training.adaptive.dto.responses.SandboxInfo;
import cz.muni.ics.kypo.training.adaptive.exceptions.CustomWebClientException;
import cz.muni.ics.kypo.training.adaptive.exceptions.ForbiddenException;
import cz.muni.ics.kypo.training.adaptive.exceptions.MicroserviceApiException;
import cz.muni.ics.kypo.training.adaptive.exceptions.errors.PythonApiError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Map;
/**
* The type User service.
@@ -105,4 +103,26 @@ public class SandboxServiceApi {
}
}
}
/**
* Gets sandbox definition id.
*
* @param poolId the pool id
* @return the sandbox definition id
*/
public SandboxDefinitionInfo getSandboxDefinitionId(Long poolId) {
try {
return sandboxServiceWebClient
.get()
.uri("/pools/{poolId}/definition", poolId)
.retrieve()
.bodyToMono(SandboxDefinitionInfo.class)
.block();
} catch (CustomWebClientException ex) {
if (ex.getStatusCode() == HttpStatus.CONFLICT) {
throw new ForbiddenException("There is no available sandbox definition for particular pool (ID: " + poolId + ").");
}
throw new MicroserviceApiException("Error when calling Python API to sandbox for particular pool (ID: " + poolId + ")", new PythonApiError(ex.getMessage()));
}
}
}
Loading