Search in sources :

Example 1 with GitLocation

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();
}
Also used : GitLocation(org.alien4cloud.git.model.GitLocation) GitHardcodedCredential(org.alien4cloud.git.model.GitHardcodedCredential) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with GitLocation

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);
}
Also used : GitLocation(org.alien4cloud.git.model.GitLocation)

Example 3 with GitLocation

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;
}
Also used : GitLocation(org.alien4cloud.git.model.GitLocation)

Example 4 with 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;
}
Also used : GitLocation(org.alien4cloud.git.model.GitLocation)

Example 5 with 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);
        }
    });
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) GitLocation(org.alien4cloud.git.model.GitLocation) PostConstruct(javax.annotation.PostConstruct)

Aggregations

GitLocation (org.alien4cloud.git.model.GitLocation)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ApiOperation (io.swagger.annotations.ApiOperation)4 GitHardcodedCredential (org.alien4cloud.git.model.GitHardcodedCredential)4 User (alien4cloud.security.model.User)3 Audit (alien4cloud.audit.annotation.Audit)2 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)1 SecretProviderCredentials (alien4cloud.deployment.model.SecretProviderCredentials)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 RestError (alien4cloud.rest.model.RestError)1 RestResponse (alien4cloud.rest.model.RestResponse)1 TopologyValidationResult (alien4cloud.topology.TopologyValidationResult)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Path (java.nio.file.Path)1 PostConstruct (javax.annotation.PostConstruct)1 SneakyThrows (lombok.SneakyThrows)1