Skip to content

Commit

Permalink
extend terraform and opentofu local deployers to support multiple ver…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
baixinsui committed Sep 26, 2024
1 parent 3f72b94 commit 2ab0974
Show file tree
Hide file tree
Showing 29 changed files with 1,045 additions and 228 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ node_modules
xpanse_deploy_ws
/openapi
.mvn/wrapper/*.jar
aes_sec
aes_sec
terraform.log
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformBootRequestFailedException;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformExecutorException;
import org.eclipse.xpanse.modules.models.billing.exceptions.ServicePriceCalculationFailed;
import org.eclipse.xpanse.modules.models.common.exceptions.InvalidDeployerToolException;
import org.eclipse.xpanse.modules.models.response.Response;
import org.eclipse.xpanse.modules.models.response.ResultType;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.ActivitiTaskNotFoundException;
Expand Down Expand Up @@ -258,4 +259,15 @@ public Response handleServicePriceCalculationFailed(ServicePriceCalculationFaile
public Response handleFileLockedException(FileLockedException ex) {
return getErrorResponse(ResultType.FILE_LOCKED, Collections.singletonList(ex.getMessage()));
}

/**
* Exception handler for InvalidDeployerToolException.
*/
@ExceptionHandler({InvalidDeployerToolException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Response handleInvalidDeployerToolException(InvalidDeployerToolException ex) {
return getErrorResponse(ResultType.INVALID_DEPLOYER_TOOL,
Collections.singletonList(ex.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.CREDENTIAL_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.DEPLOYER_VERSIONS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.MONITOR_METRICS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.REGION_AZS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.SERVICE_FLAVOR_PRICE_CACHE_NAME;
Expand Down Expand Up @@ -43,6 +44,9 @@ public class CaffeineCacheConfig {
@Value("${service.monitor.metrics.cache.expire.time.in.minutes:60}")
private long monitorMetricsCacheDuration;

@Value("${deployer.versions.cache.expire.time.in.minutes:60}")
private long deployerVersionCacheDuration;

/**
* Config cache manager with caffeine.
*
Expand All @@ -56,6 +60,7 @@ public CacheManager caffeineCacheManager() {
getServiceFlavorPriceCache());
cacheManager.registerCustomCache(CREDENTIAL_CACHE_NAME, getCredentialsCache());
cacheManager.registerCustomCache(MONITOR_METRICS_CACHE_NAME, getMonitorMetricsCache());
cacheManager.registerCustomCache(DEPLOYER_VERSIONS_CACHE_NAME, getDeployerVersionsCache());
return cacheManager;
}

Expand All @@ -71,6 +76,12 @@ private Cache<Object, Object> getServiceFlavorPriceCache() {
return Caffeine.newBuilder().expireAfterWrite(duration, TimeUnit.MINUTES).build();
}

private Cache<Object, Object> getDeployerVersionsCache() {
long duration = deployerVersionCacheDuration > 0 ? deployerVersionCacheDuration
: DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES;
return Caffeine.newBuilder().expireAfterWrite(duration, TimeUnit.MINUTES).build();
}


private Cache<Object, Object> getCredentialsCache() {
return Caffeine.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.CREDENTIAL_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.DEFAULT_CREDENTIAL_CACHE_EXPIRE_TIME_IN_SECONDS;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.DEPLOYER_VERSIONS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.MONITOR_METRICS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.REGION_AZS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.SERVICE_FLAVOR_PRICE_CACHE_NAME;
Expand Down Expand Up @@ -60,6 +61,9 @@ public class RedisCacheConfig {
@Value("${service.monitor.metrics.cache.expire.time.in.minutes:60}")
private long monitorMetricsCacheDuration;

@Value("${deployer.versions.cache.expire.time.in.minutes:60}")
private long deployerVersionCacheDuration;

@Value("${spring.data.redis.host}")
private String redisHost;

Expand All @@ -83,6 +87,7 @@ public CacheManager redisCacheManager() {
getServiceFlavorPriceCache());
builder.withCacheConfiguration(CREDENTIAL_CACHE_NAME, getCredentialCache());
builder.withCacheConfiguration(MONITOR_METRICS_CACHE_NAME, getMonitorMetricsCache());
builder.withCacheConfiguration(DEPLOYER_VERSIONS_CACHE_NAME, getDeployerVersionsCache());
return builder.build();
}

Expand Down Expand Up @@ -153,6 +158,15 @@ private RedisCacheConfiguration getMonitorMetricsCache() {
.serializeValuesWith(getRedisValueSerializer());
}

private RedisCacheConfiguration getDeployerVersionsCache() {
long duration = deployerVersionCacheDuration > 0 ? deployerVersionCacheDuration
: DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES;
return RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(duration))
.serializeKeysWith(getRedisKeySerializer())
.serializeValuesWith(getRedisValueSerializer());
}


/**
* Config redis template.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class CacheConstants {

public static final String MONITOR_METRICS_CACHE_NAME = "MONITOR_METRICS_CACHE";

public static final String DEPLOYER_VERSIONS_CACHE_NAME = "DEPLOYER_VERSIONS_CACHE";

public static final int DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES = 60;
public static final int DEFAULT_CREDENTIAL_CACHE_EXPIRE_TIME_IN_SECONDS = 3600;
public static final String CACHE_PROVIDER_CAFFEINE = "Caffeine";
Expand Down
10 changes: 10 additions & 0 deletions modules/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@
<artifactId>awaitility</artifactId>
<version>${awaitility.version}</version>
</dependency>
<dependency>
<groupId>org.semver4j</groupId>
<artifactId>semver4j</artifactId>
<version>${semver4j.version}</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Loading

0 comments on commit 2ab0974

Please sign in to comment.