Search in sources :

Example 1 with GitSubsystemException

use of org.commonjava.indy.subsys.git.GitSubsystemException in project indy by Commonjava.

the class RevisionsManager method setup.

@PostConstruct
public void setup() {
    if (!revisionsConfig.isEnabled()) {
        return;
    }
    try {
        final File dataDir = dataFileManager.getDetachedDataBasedir();
        final File gitignore = new File(dataDir, ".gitignore");
        dataDir.mkdirs();
        FileUtils.write(gitignore, join(DATA_DIR_GITIGNORES, "\n"));
        final GitConfig dataConf = new GitConfig(dataDir, revisionsConfig.getDataUpstreamUrl(), true).setRemoteBranchName(revisionsConfig.getBranchName()).setUserEmail(revisionsConfig.getUserEmail());
        dataFileGit = new GitManager(dataConf);
        // we need a TimerTask that will commit modifications periodically
        Timer timer = new Timer(true);
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                try {
                    int committed = commitDataUpdates();
                    if (committed > 0) {
                        logger.info("Commit and push data updates, size: " + committed);
                        pushDataUpdates();
                    }
                } catch (GitSubsystemException e) {
                    logger.warn("Failed to push data updates", e);
                }
            }
        }, 1000, // every 1 min
        60 * 1000);
    } catch (GitSubsystemException | IOException e) {
        throw new IllegalStateException("Failed to start revisions manager: " + e.getMessage(), e);
    } finally {
    }
}
Also used : GitManager(org.commonjava.indy.subsys.git.GitManager) Timer(java.util.Timer) TimerTask(java.util.TimerTask) GitConfig(org.commonjava.indy.subsys.git.GitConfig) GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) IOException(java.io.IOException) DataFile(org.commonjava.indy.subsys.datafile.DataFile) File(java.io.File) PostConstruct(javax.annotation.PostConstruct)

Example 2 with GitSubsystemException

use of org.commonjava.indy.subsys.git.GitSubsystemException in project indy by Commonjava.

the class RevisionsManager method getDataChangeLog.

public List<ChangeSummary> getDataChangeLog(String path, final int start, final int length) throws GitSubsystemException {
    if (!revisionsConfig.isEnabled()) {
        return Collections.emptyList();
    }
    final File basedir = dataFileManager.getDetachedDataBasedir();
    if (new File(path).isAbsolute()) {
        if (!path.startsWith(basedir.getPath())) {
            throw new GitSubsystemException("Cannot reference path outside of data basedir.");
        }
        path = Paths.get(basedir.toURI()).relativize(Paths.get(path)).toString();
    }
    final File file;
    if (isEmpty(path) || path.equals("/")) {
        file = basedir;
    } else {
        file = dataFileManager.getDataFile(path).getDetachedFile();
    }
    return dataFileGit.getChangelog(file, start, length);
}
Also used : GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) DataFile(org.commonjava.indy.subsys.datafile.DataFile) File(java.io.File)

Example 3 with GitSubsystemException

use of org.commonjava.indy.subsys.git.GitSubsystemException in project indy by Commonjava.

the class RevisionsAdminResource method pushDataGitUpdates.

@ApiOperation("Push Indy data directory content to the configured remote Git repository (if configured in the [revisions] section)")
@ApiResponses({ @ApiResponse(code = 200, message = "Push complete, or not configured"), @ApiResponse(code = 400, message = "In case the revisions add-on is disabled") })
@Path("/data/push")
@GET
public Response pushDataGitUpdates() {
    if (!config.isEnabled()) {
        return responseHelper.formatResponse(ApplicationStatus.BAD_REQUEST, "Revisions add-on is disabled");
    }
    Response response;
    try {
        revisionsManager.pushDataUpdates();
        // FIXME: Return some status
        response = Response.ok().build();
    } catch (final GitSubsystemException e) {
        logger.error("Failed to push git updates for data dir: " + e.getMessage(), e);
        response = responseHelper.formatResponse(e, "Failed to push git updates for data dir: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with GitSubsystemException

use of org.commonjava.indy.subsys.git.GitSubsystemException in project indy by Commonjava.

the class RevisionsAdminResource method doGet.

@ApiOperation("Retrieve the changelog for the Indy data directory content with the specified path, start-index, and number of results")
@ApiResponses({ @ApiResponse(code = 200, message = "JSON containing changelog entries", response = ChangeSummaryDTO.class), @ApiResponse(code = 400, message = "In case the revisions add-on is disabled") })
@Path("/data/changelog/{path: .+}")
@GET
@Produces(ApplicationContent.application_json)
public Response doGet(@PathParam("path") final String path, @QueryParam("start") final int start, @QueryParam("count") final int count) {
    if (!config.isEnabled()) {
        return responseHelper.formatResponse(ApplicationStatus.BAD_REQUEST, "Revisions add-on is disabled");
    }
    Response response;
    try {
        final List<ChangeSummary> listing = revisionsManager.getDataChangeLog(path, start, count);
        response = responseHelper.formatOkResponseWithJsonEntity(new ChangeSummaryDTO(listing));
    } catch (final GitSubsystemException e) {
        logger.error("Failed to read git changelog from data dir: " + e.getMessage(), e);
        response = responseHelper.formatResponse(e, "Failed to read git changelog from data dir.");
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ChangeSummaryDTO(org.commonjava.indy.revisions.jaxrs.dto.ChangeSummaryDTO) GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with GitSubsystemException

use of org.commonjava.indy.subsys.git.GitSubsystemException in project indy by Commonjava.

the class RevisionsAdminResource method pullDataGitUpdates.

@ApiOperation("Pull from the configured remote Git repository, updating the Indy data directory with files (merged according to configuration in the [revisions] section)")
@ApiResponses({ @ApiResponse(code = 200, message = "Pull complete"), @ApiResponse(code = 400, message = "In case the revisions add-on is disabled") })
@Path("/data/pull")
@GET
public Response pullDataGitUpdates() {
    if (!config.isEnabled()) {
        return responseHelper.formatResponse(ApplicationStatus.BAD_REQUEST, "Revisions add-on is disabled");
    }
    Response response;
    try {
        revisionsManager.pullDataUpdates();
        // FIXME: Return some status
        response = Response.ok().build();
    } catch (final GitSubsystemException e) {
        logger.error("Failed to pull git updates for data dir: " + e.getMessage(), e);
        response = responseHelper.formatResponse(e, "Failed to pull git updates for data dir: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

GitSubsystemException (org.commonjava.indy.subsys.git.GitSubsystemException)7 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponse (io.swagger.annotations.ApiResponse)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Path (javax.ws.rs.Path)4 Response (javax.ws.rs.core.Response)4 GET (javax.ws.rs.GET)3 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)3 File (java.io.File)2 ChangeSummaryDTO (org.commonjava.indy.revisions.jaxrs.dto.ChangeSummaryDTO)2 DataFile (org.commonjava.indy.subsys.datafile.DataFile)2 IOException (java.io.IOException)1 Date (java.util.Date)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 PostConstruct (javax.annotation.PostConstruct)1 Produces (javax.ws.rs.Produces)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 StoreType (org.commonjava.indy.model.core.StoreType)1 GitConfig (org.commonjava.indy.subsys.git.GitConfig)1