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 {
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations