Search in sources :

Example 1 with ArtifactStoreValidateData

use of org.commonjava.indy.data.ArtifactStoreValidateData in project indy by Commonjava.

the class StoreAdminHandler method revalidateArtifactStores.

@ApiOperation("Revalidation of Artifacts Stored on demand")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repositories was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/revalidate/all/")
@POST
public Response revalidateArtifactStores(@PathParam("packageType") String packageType, @PathParam("type") String type) {
    ArtifactStoreValidateData result = null;
    Map<String, ArtifactStoreValidateData> results = new HashMap<>();
    Response response;
    try {
        StoreType storeType = StoreType.get(type);
        List<ArtifactStore> allArtifactStores = adminController.getAllOfType(packageType, storeType);
        for (ArtifactStore artifactStore : allArtifactStores) {
            // Validate this Store
            result = adminController.validateStore(artifactStore);
            results.put(artifactStore.getKey().toString(), result);
        }
        response = responseHelper.formatOkResponseWithJsonEntity(results);
    } catch (IndyDataException ide) {
        logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
        response = responseHelper.formatResponse(ide);
    } catch (MalformedURLException mue) {
        logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
        response = responseHelper.formatResponse(mue);
    } catch (IndyWorkflowException iwe) {
        logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
        response = responseHelper.formatResponse(iwe);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with ArtifactStoreValidateData

use of org.commonjava.indy.data.ArtifactStoreValidateData in project indy by Commonjava.

the class StoreAdminHandler method revalidateArtifactStore.

@ApiOperation("Revalidation of Artifact Stored on demand based on package, type and name")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repository was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/{name}/revalidate")
@POST
public Response revalidateArtifactStore(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name) {
    ArtifactStoreValidateData result = null;
    Response response;
    try {
        final StoreType st = StoreType.get(type);
        final StoreKey key = new StoreKey(packageType, st, name);
        final ArtifactStore store = adminController.get(key);
        logger.info("=> Returning repository: {}", store);
        // Validate this Store
        result = adminController.validateStore(store);
        logger.warn("=> Result from Validating Store: " + result);
        if (result == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else {
            response = responseHelper.formatOkResponseWithJsonEntity(result);
        }
    } catch (IndyDataException ide) {
        logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
        response = responseHelper.formatResponse(ide);
    } catch (MalformedURLException mue) {
        logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
        response = responseHelper.formatResponse(mue);
    } catch (IndyWorkflowException iwe) {
        logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
        response = responseHelper.formatResponse(iwe);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) MalformedURLException(java.net.MalformedURLException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with ArtifactStoreValidateData

use of org.commonjava.indy.data.ArtifactStoreValidateData in project indy by Commonjava.

the class IndySslValidationApiTest method run.

@Test
public void run() {
    RemoteRepository storedTestRepo = null;
    RemoteRepository storedTestSslRepo = null;
    RemoteRepository storedTestAllowedRepo = null;
    try {
        HashMap<String, ArtifactStoreValidateData> remoteRepositoriesValidated = client.module(IndySslValidationClientModule.class).revalidateAllStores();
        LOGGER.info("=> All Validated Remote Repositories Response: " + remoteRepositoriesValidated);
        LOGGER.info("=> RESULT: " + remoteRepositoriesValidated.get(String.valueOf("maven:remote:central")));
        assertNotNull(remoteRepositoriesValidated);
        assertTrue(!remoteRepositoriesValidated.isEmpty());
    } catch (IndyClientException e) {
        LOGGER.warn("=> Exception in revalidating all store API call");
    }
    // REPO TESTING URL - http://repo.maven.apache.org/maven2 - NOT VALID NOT ALLOWED SSL REPO
    try {
        // first there is need for config variables to be set to false (remote.ssl.required , _internal.store.validation.enabled )
        if (configuration.isSSLRequired() == true) {
            configuration.setSslRequired(false);
        }
        if (featureConfig.getStoreValidation() == true) {
            featureConfig.setStoreValidation(false);
        }
        RemoteRepository testRepo = new RemoteRepository("maven", "test", "http://repo.maven.apache.org/maven2");
        LOGGER.info("=> Storing Remote RemoteRepository: " + testRepo.getUrl());
        client.stores().create(testRepo, "Testing Remote RemoteRepository", RemoteRepository.class);
        storedTestRepo = client.stores().load(remote, testRepo.getName(), RemoteRepository.class);
        // now there is need for config varables to be set to true (remote.ssl.required , _internal.store.validation.enabled )
        if (configuration.isSSLRequired() == false) {
            configuration.setSslRequired(true);
        }
        if (featureConfig.getStoreValidation() == false) {
            featureConfig.setStoreValidation(true);
        }
        LOGGER.info("=> Validating Remote RemoteRepository: " + testRepo.getUrl());
        ArtifactStoreValidateData remoteRepoAPIResult = client.module(IndySslValidationClientModule.class).revalidateStore(storedTestRepo);
        LOGGER.info("=> API Returned Result [Validate Remote Repo]: " + remoteRepoAPIResult);
        assertNotNull(remoteRepoAPIResult);
        assertFalse(remoteRepoAPIResult.isValid());
        assertThat(remoteRepoAPIResult.getRepositoryUrl(), is(remoteRepoAPIResult.getErrors().get("NOT_ALLOWED_SSL")));
    } catch (IndyClientException e) {
        LOGGER.warn("=> Exception in revalidating store " + storedTestRepo.getUrl() + " API call");
    }
    // REPO TESTING URL - https://repo.maven.apache.org/maven2 - VALID SSL REPO
    try {
        RemoteRepository testRepoSsl = new RemoteRepository("maven", "test-ssl", "https://repo.maven.apache" + ".org/maven2");
        LOGGER.info("=> Storing Remote RemoteRepository: " + testRepoSsl.getUrl());
        client.stores().create(testRepoSsl, "Testing SSL Remote RemoteRepository", RemoteRepository.class);
        storedTestSslRepo = client.stores().load(remote, testRepoSsl.getName(), RemoteRepository.class);
        LOGGER.info("=> Validating Remote RemoteRepository: " + testRepoSsl.getUrl());
        ArtifactStoreValidateData remoteSslRepoAPIResult = client.module(IndySslValidationClientModule.class).revalidateStore(storedTestSslRepo);
        LOGGER.info("=> API Returned Result [Validate Remote Repo]: " + remoteSslRepoAPIResult);
        assertNotNull(remoteSslRepoAPIResult);
        assertTrue(remoteSslRepoAPIResult.isValid());
        assertThat(String.valueOf(200), is(remoteSslRepoAPIResult.getErrors().get("HTTP_HEAD_STATUS")));
        assertThat(String.valueOf(200), is(remoteSslRepoAPIResult.getErrors().get("HTTP_GET_STATUS")));
    } catch (IndyClientException ice) {
        LOGGER.warn("=> Exception in revalidating store " + storedTestSslRepo + " API call");
    }
    // REPO TESTING URL - https://repo.maven.apache.org/maven2 - NOT VALID , ALLOWED , NOT AVAILABLE NON-SSL REPO
    try {
        RemoteRepository testRepoAllowed = new RemoteRepository("maven", "test-ssl", "http://127.0.0.1/maven2");
        // first there is need for config variables to be set to false (remote.ssl.required , _internal.store.validation.enabled )
        if (configuration.isSSLRequired() == true) {
            configuration.setSslRequired(false);
        }
        if (featureConfig.getStoreValidation() == true) {
            featureConfig.setStoreValidation(false);
        }
        LOGGER.info("=> Storing Remote RemoteRepository: " + testRepoAllowed.getUrl());
        client.stores().create(testRepoAllowed, "Testing SSL Remote RemoteRepository", RemoteRepository.class);
        storedTestAllowedRepo = client.stores().load(remote, testRepoAllowed.getName(), RemoteRepository.class);
        // now there is need for config varables to be set to true (remote.ssl.required , _internal.store.validation.enabled )
        if (configuration.isSSLRequired() == false) {
            configuration.setSslRequired(true);
        }
        if (featureConfig.getStoreValidation() == false) {
            featureConfig.setStoreValidation(true);
        }
        LOGGER.info("=> Validating Remote RemoteRepository: " + testRepoAllowed.getUrl());
        ArtifactStoreValidateData remoteAllowedRepoAPIResult = client.module(IndySslValidationClientModule.class).revalidateStore(storedTestSslRepo);
        LOGGER.info("=> API Returned Result [Validate Remote Repo]: " + remoteAllowedRepoAPIResult);
        assertNotNull(remoteAllowedRepoAPIResult);
        assertFalse(remoteAllowedRepoAPIResult.isValid());
        assertTrue(remoteAllowedRepoAPIResult.getErrors().keySet().contains("Exception"));
    } catch (IndyClientException ice) {
        LOGGER.warn("=> Exception in revalidating store " + storedTestAllowedRepo.getUrl() + " API call");
    }
    // GET ALL VALIDATED REMOTE REPOSITORIES
    try {
        HashMap<String, ArtifactStoreValidateData> remoteSslRepositoriesValidated = client.module(IndySslValidationClientModule.class).revalidateAllStores();
        LOGGER.info("=> All Validated Remote Repositories Response: " + remoteSslRepositoriesValidated);
        assertNotNull(remoteSslRepositoriesValidated);
        assertTrue(!remoteSslRepositoriesValidated.isEmpty());
    } catch (IndyClientException ice) {
        LOGGER.warn("=> Exception in revalidating SECOND all store API call");
    }
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) IndyClientException(org.commonjava.indy.client.core.IndyClientException) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 4 with ArtifactStoreValidateData

use of org.commonjava.indy.data.ArtifactStoreValidateData in project indy by Commonjava.

the class AbstractStoreDataManager method store.

protected boolean store(final ArtifactStore store, final ChangeSummary summary, final boolean skipIfExists, final boolean fireEvents, final EventMetadata eventMetadata) throws IndyDataException {
    if (store == null) {
        logger.warn("Tried to store null ArtifactStore!");
        return false;
    }
    AtomicReference<IndyDataException> error = new AtomicReference<>();
    logger.trace("Storing {} using operation lock: {}", store, opLocks);
    final StoreKey storeKey = store.getKey();
    logger.warn("Storing {} using operation lock: {}", store, opLocks);
    if (internalFeatureConfig != null && internalFeatureConfig.getStoreValidation() && store.getType() != group) {
        ArtifactStoreValidateData validateData = storeValidator.validate(store);
        if (!validateData.isValid()) {
            logger.warn("=> [AbstractStoreDataManager] Adding Validation Metadata to Remote Store: " + store.getKey() + " - not Valid! ");
            if (store.getMetadata() != null) {
                store.getMetadata().putAll(validateData.getErrors());
            } else {
                store.setMetadata(validateData.getErrors());
            }
        }
    }
    Function<StoreKey, Boolean> lockHandler = k -> doStore(k, store, summary, error, skipIfExists, fireEvents, eventMetadata);
    BiFunction<StoreKey, ReentrantLock, Boolean> lockFailedHandler = (k, lock) -> {
        error.set(new IndyDataException("Failed to lock: %s for STORE after %d seconds.", k, LOCK_TIMEOUT_SECONDS));
        return false;
    };
    Boolean result = opLocks.lockAnd(storeKey, LOCK_TIMEOUT_SECONDS, lockHandler, lockFailedHandler);
    if (result == null) {
        throw new IndyDataException("Store failed due to tryLock timeout.");
    }
    IndyDataException ex = error.get();
    if (ex != null) {
        throw ex;
    }
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) BiFunction(java.util.function.BiFunction) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) LoggerFactory(org.slf4j.LoggerFactory) STORE(org.commonjava.indy.db.common.StoreUpdateAction.STORE) StringUtils(org.apache.commons.lang3.StringUtils) SslValidationConfig(org.commonjava.indy.conf.SslValidationConfig) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) Map(java.util.Map) ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreEventDispatcher(org.commonjava.indy.data.StoreEventDispatcher) ArtifactStoreQuery(org.commonjava.indy.data.ArtifactStoreQuery) StoreType.group(org.commonjava.indy.model.core.StoreType.group) Collection(java.util.Collection) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) IndyConfiguration(org.commonjava.indy.conf.IndyConfiguration) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreType.hosted(org.commonjava.indy.model.core.StoreType.hosted) ArtifactStoreUpdateType(org.commonjava.indy.change.event.ArtifactStoreUpdateType) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreValidator(org.commonjava.indy.data.StoreValidator) Locker(org.commonjava.cdi.util.weft.Locker) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) DELETE(org.commonjava.indy.db.common.StoreUpdateAction.DELETE) InternalFeatureConfig(org.commonjava.indy.conf.InternalFeatureConfig) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Collections.emptySet(java.util.Collections.emptySet) ValuePipe(org.commonjava.indy.util.ValuePipe) HostedRepository(org.commonjava.indy.model.core.HostedRepository) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) MDC(org.slf4j.MDC) Collections(java.util.Collections) StoreDataManager(org.commonjava.indy.data.StoreDataManager) ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

ArtifactStoreValidateData (org.commonjava.indy.data.ArtifactStoreValidateData)4 IndyDataException (org.commonjava.indy.data.IndyDataException)3 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponse (io.swagger.annotations.ApiResponse)2 ApiResponses (io.swagger.annotations.ApiResponses)2 MalformedURLException (java.net.MalformedURLException)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Response (javax.ws.rs.core.Response)2 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 StoreType (org.commonjava.indy.model.core.StoreType)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptySet (java.util.Collections.emptySet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1