use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class FoloAdminController method recalculateRecord.
public TrackedContentDTO recalculateRecord(final String id, final String baseUrl) throws IndyWorkflowException {
TrackingKey trackingKey = new TrackingKey(id);
TrackedContent record = recordManager.get(trackingKey);
AtomicBoolean failed = new AtomicBoolean(false);
Set<TrackedContentEntry> recalculatedUploads = recalculateEntrySet(record.getUploads(), id, failed);
Set<TrackedContentEntry> recalculatedDownloads = recalculateEntrySet(record.getDownloads(), id, failed);
if (failed.get()) {
throw new IndyWorkflowException("Failed to recalculate tracking record: %s. See Indy logs for more information", id);
}
TrackedContent recalculated = new TrackedContent(record.getKey(), recalculatedUploads, recalculatedDownloads);
recordManager.replaceTrackingRecord(recalculated);
return constructContentDTO(recalculated, baseUrl);
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class FoloAdminController method renderRepositoryZip.
public File renderRepositoryZip(final String id) throws IndyWorkflowException {
final TrackingKey tk = new TrackingKey(id);
File file = filer.getRepositoryZipFile(tk).getDetachedFile();
file.getParentFile().mkdirs();
logger.debug("Retrieving tracking record for: {}", tk);
final TrackedContent record = recordManager.get(tk);
logger.debug("Got: {}", record);
if (record == null) {
throw new IndyWorkflowException(ApplicationStatus.NOT_FOUND.code(), "No tracking record available for: %s. Maybe you forgot to seal it?", tk);
}
final Set<String> seenPaths = new HashSet<>();
final List<Transfer> items = new ArrayList<>();
addTransfers(record.getUploads(), items, id, seenPaths);
addTransfers(record.getDownloads(), items, id, seenPaths);
logger.debug("Retrieved {} files. Creating zip.", items.size());
Collections.sort(items, (f, s) -> f.getPath().compareTo(s.getPath()));
try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(file))) {
for (final Transfer item : items) {
// logger.info( "Adding: {}", item );
if (item != null) {
final String path = item.getPath();
final ZipEntry ze = new ZipEntry(path);
stream.putNextEntry(ze);
InputStream itemStream = null;
try {
itemStream = item.openInputStream();
copy(itemStream, stream);
} finally {
closeQuietly(itemStream);
}
}
}
} catch (final IOException e) {
throw new IndyWorkflowException("Failed to generate repository zip from tracking record: {}. Reason: {}", e, id, e.getMessage());
}
return file;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class IndexingContentManagerDecorator method retrieve.
@Override
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Looking for indexed path: {} in: {}", path, store.getKey());
Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD);
if (transfer != null) {
logger.debug("Found indexed transfer: {}. Returning.", transfer);
return transfer;
}
StoreType type = store.getKey().getType();
if (StoreType.group == type) {
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
if (nfc.isMissing(resource)) {
logger.debug("{} is marked as missing. Returning null.", resource);
return null;
}
logger.debug("No group index hits. Devolving to member store indexes.");
KeyedLocation location = LocationUtils.toLocation(store);
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
if (specialPathInfo == null || !specialPathInfo.isMergable()) {
transfer = getIndexedMemberTransfer((Group) store, path, TransferOperation.DOWNLOAD, (member) -> {
try {
return delegate.retrieve(member, path);
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to retrieve() for member path: %s:%s. Reason: %s", member.getKey(), path, e.getMessage()), e);
}
return null;
});
if (transfer != null) {
nfc.clearMissing(resource);
return transfer;
}
logger.debug("No index hits. Delegating to main content manager for: {} in: {}", path, store);
} else {
logger.debug("Merged content. Delegating to main content manager for: {} in: {}", path, store);
transfer = delegate.retrieve(store, path, eventMetadata);
if (transfer == null) {
nfc.addMissing(resource);
}
return transfer;
}
}
transfer = delegate.retrieve(store, path, eventMetadata);
if (transfer != null) {
logger.debug("Got transfer from delegate: {} (will index)", transfer);
indexManager.indexTransferIn(transfer, store.getKey());
}
logger.debug("Returning transfer: {}", transfer);
return transfer;
}
use of org.commonjava.indy.IndyWorkflowException 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;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class MavenMetadataGenerator method writeSnapshotMetadata.
private boolean writeSnapshotMetadata(final ArtifactPathInfo info, final List<StoreResource> files, final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
// first level will contain files that have the timestamp-buildnumber version suffix...for each, we need to parse this info.
final Map<SnapshotPart, Set<ArtifactPathInfo>> infosBySnap = new HashMap<SnapshotPart, Set<ArtifactPathInfo>>();
for (final StoreResource resource : files) {
final ArtifactPathInfo resInfo = ArtifactPathInfo.parse(resource.getPath());
if (resInfo != null) {
final SnapshotPart snap = resInfo.getSnapshotInfo();
Set<ArtifactPathInfo> infos = infosBySnap.get(snap);
if (infos == null) {
infos = new HashSet<ArtifactPathInfo>();
infosBySnap.put(snap, infos);
}
infos.add(resInfo);
}
}
if (infosBySnap.isEmpty()) {
return false;
}
final List<SnapshotPart> snaps = new ArrayList<SnapshotPart>(infosBySnap.keySet());
Collections.sort(snaps);
final Transfer metadataFile = fileManager.getTransfer(store, path);
OutputStream stream = null;
try {
final Document doc = xml.newDocumentBuilder().newDocument();
final Map<String, String> coordMap = new HashMap<String, String>();
coordMap.put(ARTIFACT_ID, info.getArtifactId());
coordMap.put(GROUP_ID, info.getGroupId());
coordMap.put(VERSION, info.getVersion());
final String lastUpdated = SnapshotUtils.generateUpdateTimestamp(SnapshotUtils.getCurrentTimestamp());
doc.appendChild(doc.createElementNS(doc.getNamespaceURI(), "metadata"));
xml.createElement(doc.getDocumentElement(), null, coordMap);
xml.createElement(doc, "versioning", Collections.<String, String>singletonMap(LAST_UPDATED, lastUpdated));
SnapshotPart snap = snaps.get(snaps.size() - 1);
Map<String, String> snapMap = new HashMap<String, String>();
if (snap.isLocalSnapshot()) {
snapMap.put(LOCAL_COPY, Boolean.TRUE.toString());
} else {
snapMap.put(TIMESTAMP, SnapshotUtils.generateSnapshotTimestamp(snap.getTimestamp()));
snapMap.put(BUILD_NUMBER, Integer.toString(snap.getBuildNumber()));
}
xml.createElement(doc, "versioning/snapshot", snapMap);
for (int i = 0; i < snaps.size(); i++) {
snap = snaps.get(i);
// the last one is the most recent.
final Set<ArtifactPathInfo> infos = infosBySnap.get(snap);
for (final ArtifactPathInfo pathInfo : infos) {
snapMap = new HashMap<String, String>();
final TypeAndClassifier tc = new SimpleTypeAndClassifier(pathInfo.getType(), pathInfo.getClassifier());
final TypeMapping mapping = typeMapper.lookup(tc);
final String classifier = mapping == null ? pathInfo.getClassifier() : mapping.getClassifier();
if (classifier != null && classifier.length() > 0) {
snapMap.put(CLASSIFIER, classifier);
}
snapMap.put(EXTENSION, mapping == null ? pathInfo.getType() : mapping.getExtension());
snapMap.put(VALUE, pathInfo.getVersion());
snapMap.put(UPDATED, lastUpdated);
xml.createElement(doc, "versioning/snapshotVersions/snapshotVersion", snapMap);
}
}
final String xmlStr = xml.toXML(doc, true);
stream = metadataFile.openOutputStream(TransferOperation.GENERATE, true, eventMetadata);
stream.write(xmlStr.getBytes("UTF-8"));
} catch (final GalleyMavenXMLException e) {
throw new IndyWorkflowException("Failed to generate maven metadata file: %s. Reason: %s", e, path, e.getMessage());
} catch (final IOException e) {
throw new IndyWorkflowException("Failed to write generated maven metadata file: %s. Reason: %s", e, metadataFile, e.getMessage());
} finally {
closeQuietly(stream);
}
return true;
}
Aggregations