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;
}
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;
}
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");
}
}
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;
}
Aggregations