use of alien4cloud.model.git.CsarGitRepository in project alien4cloud by alien4cloud.
the class CsarGitRepositoryService method update.
/**
* Update informations for a given CsarGitRepository.
*
* @param id The id of the CsarGitRepository to update.
* @param repositoryUrl The new url of the CsarGitRepository
* @param username The username associated to the CsarGitRepository
* @param password The password associated to the CsarGitRepository
* @param importLocations
* @param isStoredLocally
*/
public void update(String id, String repositoryUrl, String username, String password, List<CsarGitCheckoutLocation> importLocations, boolean isStoredLocally) {
validatesRepositoryUrl(repositoryUrl);
CsarGitRepository repositoryToUpdate = getOrFail(id);
if (!repositoryToUpdate.getRepositoryUrl().equals(repositoryUrl)) {
failIfExists(repositoryUrl);
repositoryToUpdate.setRepositoryUrl(repositoryUrl);
}
if (username != null) {
repositoryToUpdate.setUsername(username);
}
if (password != null) {
repositoryToUpdate.setPassword(password);
}
repositoryToUpdate.setStoredLocally(isStoredLocally);
// just merge the existing location hash into new list so that we don't loose this information
for (CsarGitCheckoutLocation location : importLocations) {
CsarGitCheckoutLocation existingLocation = findLocationIn(location, repositoryToUpdate.getImportLocations());
if (existingLocation != null) {
location.setLastImportedHash(existingLocation.getLastImportedHash());
}
}
repositoryToUpdate.setImportLocations(importLocations);
alienDAO.save(repositoryToUpdate);
}
use of alien4cloud.model.git.CsarGitRepository in project alien4cloud by alien4cloud.
the class CsarGitRepositoryService method create.
/**
* Create a CsarGitRepository in the system to store its informations
*
* @param repositoryUrl The unique Git url of the CsarGitRepository
* @param username The username of the user
* @param password The password of the user
* @param importLocations Locations where Csar's files are store
* @param isStoredLocally The state of the the CsarGitRepository
* @return The auto-generated id of the CsarGitRepository object
*/
public String create(String repositoryUrl, String username, String password, List<CsarGitCheckoutLocation> importLocations, boolean isStoredLocally) {
validatesRepositoryUrl(repositoryUrl);
failIfExists(repositoryUrl);
if (importLocations.isEmpty()) {
throw new InvalidArgumentException("Import locations cannot be empty.");
}
// create it
CsarGitRepository csarGit = new CsarGitRepository();
csarGit.setId(UUID.randomUUID().toString());
csarGit.setRepositoryUrl(repositoryUrl);
csarGit.setUsername(username);
csarGit.setPassword(password);
csarGit.setImportLocations(importLocations);
csarGit.setStoredLocally(isStoredLocally);
alienDAO.save(csarGit);
return csarGit.getId();
}
use of alien4cloud.model.git.CsarGitRepository in project alien4cloud by alien4cloud.
the class CsarGitService method delete.
/**
* Delete an CsarGitRepository based on its id.
*
* @param id The id of the CsarGitRepository to delete.
*/
public void delete(String id) {
CsarGitRepository csarGit = csarGitRepositoryService.getOrFail(id);
if (csarGit.isStoredLocally()) {
Path repositoryPath = tempDirPath.resolve(csarGit.getId());
if (Files.isDirectory(repositoryPath)) {
FileSystemUtils.deleteRecursively(repositoryPath.toFile());
}
}
alienDAO.delete(CsarGitRepository.class, csarGit.getId());
}
use of alien4cloud.model.git.CsarGitRepository in project alien4cloud by alien4cloud.
the class CsarGitService method importFromGitRepository.
/**
* Import Cloud Service ARchives from a git repository.
*
* @param id The id to access the git repository.
* @return The result of the import (that may contains errors etc.)
*/
public List<ParsingResult<Csar>> importFromGitRepository(String id) {
CsarGitRepository csarGitRepository = csarGitRepositoryService.getOrFail(id);
List<ParsingResult<Csar>> results = Lists.newArrayList();
try {
// Iterate over locations (branches, folders etc.) and process the import
for (CsarGitCheckoutLocation csarGitCheckoutLocation : csarGitRepository.getImportLocations()) {
List<ParsingResult<Csar>> result = doImport(csarGitRepository, csarGitCheckoutLocation);
if (result != null) {
results.addAll(result);
}
}
} finally {
// cleanup
Path archiveZipRoot = tempZipDirPath.resolve(csarGitRepository.getId());
Path archiveGitRoot = tempDirPath.resolve(csarGitRepository.getId());
try {
FileUtil.delete(archiveZipRoot);
if (!csarGitRepository.isStoredLocally()) {
FileUtil.delete(archiveGitRoot);
}
} catch (IOException e) {
log.error("Failed to cleanup files after git import.", e);
}
}
return results;
}
use of alien4cloud.model.git.CsarGitRepository in project alien4cloud by alien4cloud.
the class CsarGitCRUDStepDefinition method i_get_the_GIT_repo_with_url.
@Given("^I get the GIT repo with url \"(.*?)\"$")
public void i_get_the_GIT_repo_with_url(String url) throws Throwable {
i_list_all_the_git_repositories();
CsarGitRepository csarGitRepository = getCsarGitRepository(url);
Context.getInstance().setCsarGitRepositoryId(csarGitRepository.getId());
}
Aggregations