Search in sources :

Example 46 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class TimeoutEventListener method onStoreUpdate.

public void onStoreUpdate(@Observes final ArtifactStorePostUpdateEvent event) {
    final ArtifactStoreUpdateType eventType = event.getType();
    if (eventType == ArtifactStoreUpdateType.UPDATE) {
        for (final ArtifactStore store : event) {
            final StoreKey key = store.getKey();
            final StoreType type = key.getType();
            if (type == StoreType.hosted) {
                logger.info("[ADJUST TIMEOUTS] Adjusting snapshot expirations in: {}", store.getKey());
                try {
                    scheduleManager.rescheduleSnapshotTimeouts((HostedRepository) store);
                } catch (final IndySchedulerException e) {
                    logger.error("Failed to update snapshot timeouts in: " + store.getKey(), e);
                }
            } else if (type == StoreType.remote) {
                logger.info("[ADJUST TIMEOUTS] Adjusting proxied-file expirations in: {}", store.getKey());
                try {
                    scheduleManager.rescheduleProxyTimeouts((RemoteRepository) store);
                } catch (final IndySchedulerException e) {
                    logger.error("Failed to update proxy-cache timeouts in: " + store.getKey(), e);
                }
            }
        }
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ArtifactStoreUpdateType(org.commonjava.indy.change.event.ArtifactStoreUpdateType) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 47 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class LegacyDataMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    if (!(storeDataManager instanceof DataFileStoreDataManager)) {
        logger.info("Store manager: {} is not based on DataFile's. Skipping migration.", storeDataManager.getClass().getName());
        return false;
    }
    final DataFile basedir = dataFileManager.getDataFile(INDY_STORE);
    final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Migrating legacy store definitions.");
    if (!basedir.exists()) {
        return false;
    }
    StoreType[] storeTypes = StoreType.values();
    final String[] dirs = basedir.list();
    if (dirs == null || dirs.length < 1) {
        return false;
    }
    Map<String, String> migrationCandidates = new HashMap<>();
    //noinspection ConstantConditions
    Stream.of(storeTypes).forEach(type -> {
        File[] files = basedir.getDetachedFile().toPath().resolve(type.singularEndpointName()).toFile().listFiles((dir, fname) -> fname.endsWith(".json"));
        if (files != null) {
            Stream.of(files).forEach((f) -> {
                String src = Paths.get(type.singularEndpointName(), f.getName()).toString();
                String target = Paths.get(MAVEN_PKG_KEY, type.singularEndpointName(), f.getName()).toString();
                migrationCandidates.put(src, target);
            });
        }
    });
    boolean changed = false;
    for (Map.Entry<String, String> entry : migrationCandidates.entrySet()) {
        DataFile src = dataFileManager.getDataFile(INDY_STORE, entry.getKey());
        DataFile target = dataFileManager.getDataFile(INDY_STORE, entry.getValue());
        if (target.exists()) {
            continue;
        }
        DataFile targetDir = target.getParent();
        if (!targetDir.exists() && !targetDir.mkdirs()) {
            throw new IndyLifecycleException("Cannot make directory: %s.", targetDir.getPath());
        } else if (!targetDir.isDirectory()) {
            throw new IndyLifecycleException("Not a directory: %s.", targetDir.getPath());
        }
        try {
            logger.info("Migrating definition {}", src.getPath());
            final String json = src.readString();
            final String migrated = objectMapper.patchLegacyStoreJson(json);
            target.writeString(migrated, summary);
            changed = true;
        } catch (final IOException e) {
            throw new IndyLifecycleException("Failed to migrate artifact-store definition from: %s to: %s. Reason: %s", e, src, target, e.getMessage(), e);
        }
    }
    if (changed) {
        try {
            storeDataManager.reload();
        } catch (IndyDataException e) {
            throw new IndyLifecycleException("Failed to reload migrated store definitions: %s", e, e.getMessage());
        }
    }
    return changed;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) DataFile(org.commonjava.indy.subsys.datafile.DataFile) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) DataFile(org.commonjava.indy.subsys.datafile.DataFile) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 48 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class StoreURIMatcher method getStoreFolderStoreType.

public StoreType getStoreFolderStoreType(final String uri) {
    if (!matches()) {
        return null;
    }
    if (hasStoreType()) {
        final String typePart = matcher.group(STORE_TYPE_GRP);
        //            logger.info( "Type part of name is: '{}'", typePart );
        final StoreType type = StoreType.get(typePart);
        return type;
    }
    return null;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType)

Example 49 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class TrackedContentEntry method readExternal.

@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
    trackingKey = (TrackingKey) in.readObject();
    final String storeKeyName = (String) in.readObject();
    final StoreType storeType = StoreType.get((String) in.readObject());
    storeKey = new StoreKey(storeType, storeKeyName);
    final String accessChannelStr = (String) in.readObject();
    accessChannel = "".equals(accessChannelStr) ? null : AccessChannel.valueOf(accessChannelStr);
    final String pathStr = (String) in.readObject();
    path = "".equals(pathStr) ? null : pathStr;
    final String originUrlStr = (String) in.readObject();
    originUrl = "".equals(originUrlStr) ? null : originUrlStr;
    final String effectStr = (String) in.readObject();
    effect = "".equals(effectStr) ? null : StoreEffect.valueOf(effectStr);
    final String md5Str = (String) in.readObject();
    md5 = "".equals(md5Str) ? null : md5Str;
    final String sha1Str = (String) in.readObject();
    sha1 = "".equals(sha1Str) ? null : sha1Str;
    final String sha256Str = (String) in.readObject();
    sha256 = "".equals(sha256Str) ? null : sha256Str;
    size = (Long) in.readObject();
    index = in.readLong();
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 50 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class AffectedStoreRecordTest method recordUploadsSorted.

@Test
public void recordUploadsSorted() throws Exception {
    final StoreType type = StoreType.group;
    final String name = "test-group";
    final AffectedStoreRecord record = new AffectedStoreRecord(new StoreKey(type, name));
    record.add("/path/two", StoreEffect.UPLOAD);
    record.add("/path/one", StoreEffect.UPLOAD);
    assertThat(record.getUploadedPaths().iterator().next(), equalTo("/path/one"));
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Aggregations

StoreType (org.commonjava.indy.model.core.StoreType)53 StoreKey (org.commonjava.indy.model.core.StoreKey)43 Response (javax.ws.rs.core.Response)25 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)25 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)22 ApiOperation (io.swagger.annotations.ApiOperation)21 ApiResponse (io.swagger.annotations.ApiResponse)21 Path (javax.ws.rs.Path)19 ApiResponses (io.swagger.annotations.ApiResponses)18 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)18 IOException (java.io.IOException)13 GET (javax.ws.rs.GET)12 Produces (javax.ws.rs.Produces)12 List (java.util.List)10 Inject (javax.inject.Inject)10 DELETE (javax.ws.rs.DELETE)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 ResponseUtils.markDeprecated (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated)9 IndyDataException (org.commonjava.indy.data.IndyDataException)8 Transfer (org.commonjava.maven.galley.model.Transfer)8