Search in sources :

Example 1 with IndyWorkflowException

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 2 with IndyWorkflowException

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;
}
Also used : InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) ZipOutputStream(java.util.zip.ZipOutputStream) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) FileOutputStream(java.io.FileOutputStream) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) Transfer(org.commonjava.maven.galley.model.Transfer) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with IndyWorkflowException

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;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger)

Example 4 with IndyWorkflowException

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;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) StoreKey(org.commonjava.indy.model.core.StoreKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 5 with IndyWorkflowException

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) GalleyMavenXMLException(org.commonjava.maven.galley.maven.parse.GalleyMavenXMLException) IOException(java.io.IOException) Document(org.w3c.dom.Document) StoreResource(org.commonjava.indy.content.StoreResource) SnapshotPart(org.commonjava.maven.atlas.ident.version.part.SnapshotPart) SimpleTypeAndClassifier(org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier) TypeAndClassifier(org.commonjava.maven.atlas.ident.ref.TypeAndClassifier) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArtifactPathInfo(org.commonjava.maven.atlas.ident.util.ArtifactPathInfo) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleTypeAndClassifier(org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier) TypeMapping(org.commonjava.maven.galley.model.TypeMapping)

Aggregations

IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)109 Response (javax.ws.rs.core.Response)40 Transfer (org.commonjava.maven.galley.model.Transfer)39 IOException (java.io.IOException)36 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)36 StoreKey (org.commonjava.indy.model.core.StoreKey)36 ApiOperation (io.swagger.annotations.ApiOperation)35 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)34 ApiResponse (io.swagger.annotations.ApiResponse)33 Path (javax.ws.rs.Path)32 StoreType (org.commonjava.indy.model.core.StoreType)26 IndyDataException (org.commonjava.indy.data.IndyDataException)25 GET (javax.ws.rs.GET)24 Logger (org.slf4j.Logger)22 ApiResponses (io.swagger.annotations.ApiResponses)21 ArrayList (java.util.ArrayList)19 Produces (javax.ws.rs.Produces)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 InputStream (java.io.InputStream)15 List (java.util.List)13