use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class PromotionHelper method clearStoreNFC.
/**
* Clear NFC for the source store and affected groups.
*
* @param sourcePaths The set of paths that need to be cleared from the NFC.
* @param store The store whose affected groups should have their NFC entries cleared
*/
public void clearStoreNFC(final Set<String> sourcePaths, final ArtifactStore store, final Set<Group> affectedGroups) {
Set<String> paths = sourcePaths.stream().map(sp -> sp.startsWith("/") && sp.length() > 1 ? sp.substring(1) : sp).collect(Collectors.toSet());
paths.forEach(path -> {
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
logger.trace("Clearing NFC path: {} from: {}\n\tResource: {}", path, store.getKey(), resource);
nfc.clearMissing(resource);
});
Set<Group> groups;
if (affectedGroups != null) {
groups = affectedGroups;
} else {
try {
groups = storeManager.query().getGroupsAffectedBy(store.getKey());
} catch (IndyDataException e) {
logger.warn("Failed to clear NFC for groups affected by " + store.getKey(), e);
return;
}
}
if (groups != null) {
groups.forEach(group -> {
KeyedLocation gl = LocationUtils.toLocation(group);
paths.forEach(path -> {
ConcreteResource resource = new ConcreteResource(gl, path);
logger.trace("Clearing NFC path: {} from: {}\n\tResource: {}", path, group.getKey(), resource);
nfc.clearMissing(resource);
});
});
}
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ProxyResponseHelper method getRemoteRepositoryName.
/**
* if repo with this name already exists, we need to use a different name
*/
private String getRemoteRepositoryName(URL url) throws IndyDataException {
final String name = repoCreator.formatId(url.getHost(), getPort(url), 0, null, StoreType.remote);
logger.debug("Looking for remote repo starts with name: {}", name);
AbstractProxyRepositoryCreator abstractProxyRepositoryCreator = null;
if (repoCreator instanceof AbstractProxyRepositoryCreator) {
abstractProxyRepositoryCreator = (AbstractProxyRepositoryCreator) repoCreator;
}
if (abstractProxyRepositoryCreator == null) {
return name;
}
Predicate<ArtifactStore> filter = abstractProxyRepositoryCreator.getNameFilter(name);
List<String> l = storeManager.query().getAllRemoteRepositories(GENERIC_PKG_KEY).stream().filter(filter).map(repository -> repository.getName()).collect(Collectors.toList());
if (l.isEmpty()) {
return name;
}
return abstractProxyRepositoryCreator.getNextName(l);
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class DeprecatedStoreAdminHandler method getAll.
@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type).toString();
Consumer<Response.ResponseBuilder> modifier = (rb) -> responseHelper.markDeprecated(rb, altPath);
final StoreType st = StoreType.get(type);
Response response;
try {
final List<ArtifactStore> stores = adminController.getAllOfType(st);
logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
response = responseHelper.formatOkResponseWithJsonEntity(dto, modifier);
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = responseHelper.formatResponse(e, modifier);
}
return response;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class StoreAdminHandler method create.
@ApiOperation("Create a new store")
@ApiResponses({ @ApiResponse(code = 201, response = ArtifactStore.class, message = "The store was created"), @ApiResponse(code = 409, message = "A store with the specified type and name already exists") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.model.core.ArtifactStore", value = "The artifact store definition JSON") })
@POST
@Consumes(ApplicationContent.application_json)
@Produces(ApplicationContent.application_json)
public Response create(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @Context final UriInfo uriInfo, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
final StoreType st = StoreType.get(type);
Response response = null;
String json = null;
try {
json = IOUtils.toString(request.getInputStream());
// logger.warn("=> JSON: " + json);
json = objectMapper.patchLegacyStoreJson(json);
} catch (final IOException e) {
final String message = "Failed to read " + st.getStoreClass().getSimpleName() + " from request body.";
logger.error(message, e);
response = responseHelper.formatResponse(e, message);
}
if (response != null) {
return response;
}
ArtifactStore store = null;
try {
store = objectMapper.readValue(json, st.getStoreClass());
} catch (final IOException e) {
final String message = "Failed to parse " + st.getStoreClass().getSimpleName() + " from request body.";
logger.error(message, e);
response = responseHelper.formatResponse(e, message);
}
if (response != null) {
return response;
}
logger.info("\n\nGot artifact store: {}\n\n", store);
try {
String user = securityManager.getUser(securityContext, request);
if (adminController.store(store, user, false)) {
final URI uri = uriInfo.getBaseUriBuilder().path("/api/admin/stores").path(store.getPackageType()).path(store.getType().singularEndpointName()).build(store.getName());
response = responseHelper.formatCreatedResponseWithJsonEntity(uri, store);
} else {
response = status(CONFLICT).entity("{\"error\": \"Store already exists.\"}").type(application_json).build();
}
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = responseHelper.formatResponse(e);
}
return response;
}
use of org.commonjava.indy.model.core.ArtifactStore 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;
}
Aggregations