Search in sources :

Example 1 with AutoProxCalculation

use of org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation in project indy by Commonjava.

the class AutoProxCalculatorResource method eval.

@ApiOperation(value = "Calculate the effects of referencing a store with the given type and name to determine what AutoProx will auto-create", response = AutoProxCalculation.class)
@ApiResponse(code = 200, message = "Result of calculation")
@Path("/{packageType}/{type: (hosted|group|remote)}/{name}")
@GET
@Produces(ApplicationContent.application_json)
public Response eval(@PathParam("packageType") final String packageType, @PathParam("type") final String type, @PathParam("name") final String remoteName) {
    Response response = checkEnabled();
    if (response != null) {
        return response;
    }
    try {
        StoreKey key = new StoreKey(packageType, StoreType.get(type), remoteName);
        final AutoProxCalculation calc = controller.eval(key);
        response = formatOkResponseWithJsonEntity(serializer.writeValueAsString(calc == null ? Collections.singletonMap("error", "Nothing was created") : calc));
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to create demo RemoteRepository for: '%s'. Reason: %s", remoteName, e.getMessage()), e);
        response = formatResponse(e);
    } catch (final JsonProcessingException e) {
        logger.error(String.format("Failed to create demo RemoteRepository for: '%s'. Reason: %s", remoteName, e.getMessage()), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) StoreKey(org.commonjava.indy.model.core.StoreKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 2 with AutoProxCalculation

use of org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation in project indy by Commonjava.

the class CalculateGroupReturn400WhenDisabledTest method calculate.

@Test(expected = IndyClientException.class)
public void calculate() throws Exception {
    final String name = "test";
    final AutoProxCalculation calculation = module.calculateRuleOutput(StoreType.group, name);
}
Also used : AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) Test(org.junit.Test)

Example 3 with AutoProxCalculation

use of org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation in project indy by Commonjava.

the class CalculateHostedRepoTest method calculate.

@Test
public void calculate() throws Exception {
    final String name = "test";
    final AutoProxCalculation calculation = module.calculateRuleOutput(StoreType.hosted, name);
    assertThat(calculation.getRuleName(), equalTo("0001-simple-rule"));
    assertThat(calculation.getSupplementalStores().isEmpty(), equalTo(true));
    final HostedRepository remote = (HostedRepository) calculation.getStore();
    assertThat(remote.isAllowReleases(), equalTo(true));
    assertThat(remote.isAllowSnapshots(), equalTo(true));
}
Also used : AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 4 with AutoProxCalculation

use of org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation in project indy by Commonjava.

the class CalculateGroupTest method calculate.

@Test
public void calculate() throws Exception {
    final String name = "test";
    final AutoProxCalculation calculation = module.calculateRuleOutput(StoreType.group, name);
    assertThat(calculation.getRuleName(), equalTo("0001-simple-rule"));
    final List<ArtifactStore> supplemental = calculation.getSupplementalStores();
    assertThat(supplemental.size(), equalTo(4));
    final Group store = (Group) calculation.getStore();
    assertThat(store.getName(), equalTo(name));
    int idx = 0;
    ArtifactStore supp = supplemental.get(idx);
    assertThat(supp.getName(), equalTo(name));
    assertThat(supp instanceof HostedRepository, equalTo(true));
    final HostedRepository hosted = (HostedRepository) supp;
    assertThat(hosted.isAllowReleases(), equalTo(true));
    assertThat(hosted.isAllowSnapshots(), equalTo(true));
    idx++;
    supp = supplemental.get(idx);
    assertThat(supp.getName(), equalTo(name));
    assertThat(supp instanceof RemoteRepository, equalTo(true));
    final RemoteRepository remote = (RemoteRepository) supp;
    assertThat(remote.getUrl(), equalTo("http://localhost:1000/target/" + name));
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 5 with AutoProxCalculation

use of org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation in project indy by Commonjava.

the class CalculateRemoteRepoTest method calculate.

@Test
public void calculate() throws Exception {
    final String name = "test";
    final AutoProxCalculation calculation = module.calculateRuleOutput(StoreType.remote, name);
    assertThat(calculation.getRuleName(), equalTo("0001-simple-rule"));
    assertThat(calculation.getSupplementalStores().isEmpty(), equalTo(true));
    final RemoteRepository remote = (RemoteRepository) calculation.getStore();
    assertThat(remote.getUrl(), equalTo("http://localhost:1000/target/" + name));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) Test(org.junit.Test)

Aggregations

AutoProxCalculation (org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation)5 Test (org.junit.Test)4 HostedRepository (org.commonjava.indy.model.core.HostedRepository)2 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)1 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)1 Group (org.commonjava.indy.model.core.Group)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1