use of org.alien4cloud.git.model.GitLocation in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentGitController method getByEnvironmentId.
@ApiOperation(value = "Retrieve information about a git repository using environment Id.")
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("isAuthenticated()")
public RestResponse<GitLocation> getByEnvironmentId(@ApiParam(value = "Application id", required = true) @PathVariable String applicationId, @ApiParam(value = "Environment id", required = true) @PathVariable String environmentId) {
checkEnvironmentAuthorization(applicationId, environmentId);
GitLocation gitLocation = gitLocationDao.findDeploymentSetupLocation(applicationId, environmentId);
if (gitLocation.isLocal()) {
gitLocation.setUrl(GitLocation.LOCAL_PREFIX);
}
gitLocation.setCredential(new GitHardcodedCredential());
return RestResponseBuilder.<GitLocation>builder().data(gitLocation).build();
}
use of org.alien4cloud.git.model.GitLocation in project alien4cloud by alien4cloud.
the class ResourceUpdateInterceptorForGit method checkoutVersionBranch.
public void checkoutVersionBranch(ApplicationEnvironment environment) {
GitLocation location = gitLocationDao.findDeploymentSetupLocation(environment.getApplicationId(), environment.getId());
location.setBranch(environment.getTopologyVersion());
localGitManager.checkout(location);
}
use of org.alien4cloud.git.model.GitLocation in project alien4cloud by alien4cloud.
the class GitLocationDao method findApplicationVariablesLocation.
public GitLocation findApplicationVariablesLocation(String applicationId) {
String id = GitLocation.IdBuilder.forApplicationVariables(applicationId);
// does a remote git has been configured ?
GitLocation gitLocation = alienDao.findById(GitLocation.class, id);
if (gitLocation == null) {
// return alien managed git
gitLocation = gitLocationService.getApplicationVariablesLocalGitLocation(applicationId);
}
return gitLocation;
}
use of org.alien4cloud.git.model.GitLocation in project alien4cloud by alien4cloud.
the class GitLocationDao method findDeploymentSetupLocation.
public GitLocation findDeploymentSetupLocation(String applicationId, String environmentId) {
String id = GitLocation.IdBuilder.forDeploymentSetup(applicationId, environmentId);
// does a remote git has been configured ?
GitLocation gitLocation = alienDao.findById(GitLocation.class, id);
if (gitLocation == null) {
// return alien managed git
gitLocation = gitLocationService.getDeploymentSetupLocalGitLocation(applicationId, environmentId);
}
return gitLocation;
}
use of org.alien4cloud.git.model.GitLocation in project alien4cloud by alien4cloud.
the class ResourceUpdateInterceptorForGit method configure.
@PostConstruct
public void configure() {
resourceUpdateInterceptor.getOnNewEnvironment().add(applicationEnvironment -> {
// create local git if needed
checkoutVersionBranch(applicationEnvironment);
});
resourceUpdateInterceptor.getOnEnvironmentTopologyVersionChanged().add(topologyVersionChangedInfo -> {
// checkout the new branch
checkoutVersionBranch(topologyVersionChangedInfo.getEnvironment());
});
resourceUpdateInterceptor.getOnTopologyVersionUpdated().add(topologyVersionUpdated -> {
String newBaseVersion = StringUtils.replaceFirst(topologyVersionUpdated.getTo().getVersion(), "-SNAPSHOT", "");
String fromBaseVersion = StringUtils.replaceFirst(topologyVersionUpdated.getFrom().getVersion(), "-SNAPSHOT", "");
Map<String, String> branchNameFromTo = Maps.newHashMap();
topologyVersionUpdated.getFrom().getTopologyVersions().forEach((fromTopologyVersion, applicationTopologyVersion) -> {
String updatedVersion = StringUtils.replaceFirst(fromTopologyVersion, fromBaseVersion, newBaseVersion);
if (topologyVersionUpdated.getTo().isReleased()) {
updatedVersion = StringUtils.replaceFirst(updatedVersion, "-SNAPSHOT", "");
}
branchNameFromTo.put(fromTopologyVersion, updatedVersion);
});
ApplicationEnvironment[] environments = applicationEnvironmentService.getByApplicationId(topologyVersionUpdated.getFrom().getApplicationId());
for (ApplicationEnvironment environment : environments) {
GitLocation gitLocation = gitLocationDao.findDeploymentSetupLocation(environment.getApplicationId(), environment.getId());
localGitManager.renameBranches(gitLocation, branchNameFromTo);
}
});
}
Aggregations