Search in sources :

Example 6 with StoreType

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

the class AffectedStoreRecordTest method roundTripEmptyRecordToJson.

@Test
public void roundTripEmptyRecordToJson() throws Exception {
    final StoreType type = StoreType.group;
    final String name = "test-group";
    final AffectedStoreRecord record = new AffectedStoreRecord(new StoreKey(type, name));
    final String json = mapper.writeValueAsString(record);
    System.out.println(json);
    final AffectedStoreRecord result = mapper.readValue(json, AffectedStoreRecord.class);
    assertThat(result, notNullValue());
    assertThat(result.getKey(), equalTo(record.getKey()));
    assertThat(result.getDownloadedPaths(), nullValue());
    assertThat(result.getUploadedPaths(), nullValue());
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 7 with StoreType

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

the class AffectedStoreRecordTest method roundTripRecordWithTwoDownloadsToJson.

@Test
public void roundTripRecordWithTwoDownloadsToJson() throws Exception {
    final StoreType type = StoreType.group;
    final String name = "test-group";
    final AffectedStoreRecord record = new AffectedStoreRecord(new StoreKey(type, name));
    record.add("/path/one", StoreEffect.DOWNLOAD);
    record.add("/path/two", StoreEffect.DOWNLOAD);
    final String json = mapper.writeValueAsString(record);
    System.out.println(json);
    final AffectedStoreRecord result = mapper.readValue(json, AffectedStoreRecord.class);
    assertThat(result, notNullValue());
    assertThat(result.getKey(), equalTo(record.getKey()));
    assertThat(result.getDownloadedPaths(), equalTo(record.getDownloadedPaths()));
    assertThat(result.getUploadedPaths(), nullValue());
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 8 with StoreType

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

the class DataFileStoreDataManager method readDefinitions.

@PostConstruct
public void readDefinitions() {
    final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Reading definitions from disk, culling invalid definition files.");
    try {
        DataFile[] packageDirs = manager.getDataFile(INDY_STORE).listFiles((f) -> true);
        for (DataFile pkgDir : packageDirs) {
            for (StoreType type : StoreType.values()) {
                DataFile[] files = pkgDir.getChild(type.singularEndpointName()).listFiles(f -> true);
                if (files != null) {
                    for (final DataFile f : files) {
                        try {
                            final String json = f.readString();
                            final ArtifactStore store = serializer.readValue(json, type.getStoreClass());
                            if (store == null) {
                                f.delete(summary);
                            } else {
                                storeArtifactStore(store, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, LOAD_FROM_DISK));
                            }
                        } catch (final IOException e) {
                            logger.error(String.format("Failed to load %s store: %s. Reason: %s", type, f, e.getMessage()), e);
                        }
                    }
                }
            }
        }
        started = true;
    } catch (final IndyDataException e) {
        throw new IllegalStateException("Failed to start store data manager: " + e.getMessage(), e);
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) PostConstruct(javax.annotation.PostConstruct)

Example 9 with StoreType

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

the class TimeoutEventListener method onFileAccessEvent.

public void onFileAccessEvent(@Observes final FileAccessEvent event) {
    // TODO: handle this stuff in Weft somehow...
    Map original = MDC.getCopyOfContextMap();
    try {
        MDC.setContextMap(event.getMDCMap());
        final StoreKey key = getKey(event);
        if (key != null) {
            final Transfer transfer = event.getTransfer();
            final StoreType type = key.getType();
            if (type == StoreType.hosted) {
                try {
                    scheduleManager.setSnapshotTimeouts(key, transfer.getPath());
                } catch (final IndySchedulerException e) {
                    logger.error("Failed to set snapshot timeouts related to: " + transfer, e);
                }
            } else if (type == StoreType.remote) {
                SpecialPathInfo info = specialPathManager.getSpecialPathInfo(transfer);
                if (info == null || !info.isMetadata()) {
                    logger.debug("Accessed resource {} timeout will be reset.", transfer);
                    try {
                        scheduleManager.setProxyTimeouts(key, transfer.getPath());
                    } catch (final IndySchedulerException e) {
                        logger.error("Failed to set proxy-cache timeouts related to: " + transfer, e);
                    }
                } else {
                    logger.debug("Accessed resource {} is metadata. NOT rescheduling timeout!", transfer);
                }
            }
        }
    } finally {
        if (original != null && !original.isEmpty()) {
            MDC.setContextMap(original);
        } else {
            MDC.setContextMap(Collections.emptyMap());
        }
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Transfer(org.commonjava.maven.galley.model.Transfer) Map(java.util.Map) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 10 with StoreType

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

the class MaintenanceHandler method deprecatedRescan.

@ApiOperation("[Deprecated] Rescan all content in the specified repository to re-initialize metadata, capture missing index keys, etc.")
@ApiResponse(code = 200, message = "Rescan was started successfully. (NOTE: There currently is no way to determine when rescanning is complete.)")
@Path("/rescan/{type: (hosted|group|remote)}/{name}")
@GET
@Deprecated
public Response deprecatedRescan(@ApiParam(value = "The type of store / repository", allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam("The name of the store / repository") @PathParam("name") final String name) {
    final StoreType storeType = StoreType.get(type);
    String altPath = Paths.get("/api/admin/maint", MAVEN_PKG_KEY, type, name).toString();
    final StoreKey key = new StoreKey(storeType, name);
    Response response;
    try {
        contentController.rescan(key);
        response = markDeprecated(Response.ok(), altPath).build();
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to rescan: %s. Reason: %s", key, e.getMessage()), e);
        response = formatResponse(e, rb -> markDeprecated(rb, altPath));
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) 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) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

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