use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class PromoteResource method promotePaths.
@ApiOperation("Promote paths from a source repository into a target repository/group (subject to validation).")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON request specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteRequest")
@Path("/paths/promote")
@POST
@Consumes(ApplicationContent.application_json)
public Response promotePaths(@Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
PathsPromoteRequest req = null;
Response response = null;
try {
final String json = IOUtils.toString(request.getInputStream());
logger.info("Got promotion request:\n{}", json);
req = mapper.readValue(json, PathsPromoteRequest.class);
} catch (final IOException e) {
response = formatResponse(e, "Failed to read DTO from request body.");
}
if (response != null) {
return response;
}
try {
PackageTypeDescriptor packageTypeDescriptor = PackageTypes.getPackageTypeDescriptor(req.getSource().getPackageType());
final String baseUrl = uriInfo.getBaseUriBuilder().path(packageTypeDescriptor.getContentRestBasePath()).build(req.getSource().getType().singularEndpointName(), req.getSource().getName()).toString();
final PathsPromoteResult result = manager.promotePaths(req, baseUrl);
// TODO: Amend response status code based on presence of error? This would have consequences for client API...
response = formatOkResponseWithJsonEntity(result, mapper);
} catch (PromotionException | IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class PromoteResource method resumePaths.
@ApiOperation("RESUME promotion of paths from a source repository into a target repository/group (subject to validation), presumably after a previous failure condition has been corrected.")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON result from previous attempt, specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteResult")
@Path("/paths/resume")
@POST
@Consumes(ApplicationContent.application_json)
public Response resumePaths(@Context final HttpServletRequest request) {
PathsPromoteResult result = null;
Response response = null;
try {
result = mapper.readValue(request.getInputStream(), PathsPromoteResult.class);
} catch (final IOException e) {
response = formatResponse(e, "Failed to read DTO from request body.");
}
if (response != null) {
return response;
}
try {
result = manager.resumePathsPromote(result);
// TODO: Amend response status code based on presence of error? This would have consequences for client API...
response = formatOkResponseWithJsonEntity(result, mapper);
} catch (PromotionException | IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class PromoteResource method rollbackPaths.
@ApiOperation("Rollback promotion of any completed paths to a source repository from a target repository/group.")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON result from previous attempt, specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteResult")
@Path("/paths/rollback")
@POST
@Consumes(ApplicationContent.application_json)
public Response rollbackPaths(@Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
PathsPromoteResult result = null;
Response response = null;
try {
result = mapper.readValue(request.getInputStream(), PathsPromoteResult.class);
} catch (final IOException e) {
response = formatResponse(e, "Failed to read DTO from request body.");
}
if (response != null) {
return response;
}
try {
result = manager.rollbackPathsPromote(result);
// TODO: Amend response status code based on presence of error? This would have consequences for client API...
response = formatOkResponseWithJsonEntity(result, mapper);
} catch (PromotionException | IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class IndexingContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final StoreKey storeKey, final String path, final TransferOperation op) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
Transfer transfer = getIndexedTransfer(storeKey, null, path, TransferOperation.DOWNLOAD);
if (transfer != null) {
logger.debug("Returning indexed transfer: {}", transfer);
return transfer;
}
ArtifactStore store;
try {
store = storeDataManager.getArtifactStore(storeKey);
} catch (IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup ArtifactStore: %s for NFC handling. Reason: %s", e, storeKey, e.getMessage());
}
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
StoreType type = storeKey.getType();
if (StoreType.group == type) {
Group g = (Group) store;
if (g == null) {
throw new IndyWorkflowException("Cannot find requested group: %s", storeKey);
}
if (nfc.isMissing(resource)) {
logger.debug("NFC / MISSING: {}", resource);
return null;
}
logger.debug("No group index hits. Devolving to member store indexes.");
for (StoreKey key : g.getConstituents()) {
transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
try {
return delegate.getTransfer(member, path, op);
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to getTransfer() for member path: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
}
return null;
});
if (transfer != null) {
logger.debug("Returning indexed transfer: {} from member: {}", transfer, key);
return transfer;
}
}
}
transfer = delegate.getTransfer(storeKey, path, op);
if (transfer != null) {
logger.debug("Indexing transfer: {}", transfer);
indexManager.indexTransferIn(transfer, storeKey);
}
return transfer;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class IndexingContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD);
if (transfer != null) {
return transfer;
}
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
StoreType type = store.getKey().getType();
if (StoreType.group == type) {
if (!nfc.isMissing(resource)) {
logger.debug("No group index hits. Devolving to member store indexes.");
transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
try {
return delegate.getTransfer(member, path, op);
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to getTransfer() for: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
}
return null;
});
if (transfer != null) {
return transfer;
}
} else {
logger.debug("NFC marks {} as missing. Returning null.", resource);
return null;
}
}
transfer = delegate.getTransfer(store, path, op);
// index the transfer only if it exists, it cannot be null at this point
if (transfer != null && transfer.exists()) {
indexManager.indexTransferIn(transfer, store.getKey());
}
logger.debug("Returning transfer: {}", transfer);
return transfer;
}
Aggregations