Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend terraform and opentofu local deployers to support multiple versions #1980

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -56,6 +57,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 +73,10 @@ private Cache<Object, Object> getServiceFlavorPriceCache() {
return Caffeine.newBuilder().expireAfterWrite(duration, TimeUnit.MINUTES).build();
}

private Cache<Object, Object> getDeployerVersionsCache() {
return Caffeine.newBuilder().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 @@ -83,6 +84,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 @@ -123,24 +125,25 @@ private String getRedisEndpoint() {
private RedisCacheConfiguration getRegionAzsCache() {
long duration = regionAzsCacheDuration > 0 ? regionAzsCacheDuration
: DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES;
return RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(duration))
.serializeKeysWith(getRedisKeySerializer())
.serializeValuesWith(getRedisValueSerializer());
return RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(duration))
.serializeKeysWith(getStringRedisSerializer())
.serializeValuesWith(getJsonRedisSerializer());
}

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

private RedisCacheConfiguration getCredentialCache() {
return RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofSeconds(DEFAULT_CREDENTIAL_CACHE_EXPIRE_TIME_IN_SECONDS))
.serializeKeysWith(getRedisKeySerializer())
.serializeKeysWith(getStringRedisSerializer())
.serializeValuesWith(getCredentialValueSerializer());
}

Expand All @@ -149,8 +152,14 @@ private RedisCacheConfiguration getMonitorMetricsCache() {
: DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES;
return RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(duration))
.serializeKeysWith(getRedisKeySerializer())
.serializeValuesWith(getRedisValueSerializer());
.serializeKeysWith(getStringRedisSerializer())
.serializeValuesWith(getJsonRedisSerializer());
}

private RedisCacheConfiguration getDeployerVersionsCache() {
return RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(getStringRedisSerializer())
.serializeValuesWith(getJdkRedisSerializer());
}


Expand Down Expand Up @@ -200,16 +209,23 @@ private void checkRedisIsAvailable() throws RuntimeException {
}


private RedisSerializationContext.SerializationPair<String> getRedisKeySerializer() {
private RedisSerializationContext.SerializationPair<String> getStringRedisSerializer() {
return RedisSerializationContext.SerializationPair.fromSerializer(
new StringRedisSerializer());
}

private RedisSerializationContext.SerializationPair<Object> getRedisValueSerializer() {
// Jackson2JsonRedisSerializer for Object.
private RedisSerializationContext.SerializationPair<Object> getJsonRedisSerializer() {
return RedisSerializationContext.SerializationPair.fromSerializer(
new Jackson2JsonRedisSerializer<>(Object.class));
}

// JdkSerializationRedisSerializer for Set, Array, Map etc.
private RedisSerializationContext.SerializationPair<Object> getJdkRedisSerializer() {
return RedisSerializationContext.SerializationPair.fromSerializer(
new JdkSerializationRedisSerializer());
}

private RedisSerializationContext
.SerializationPair<AbstractCredentialInfo> getCredentialValueSerializer() {
return RedisSerializationContext.SerializationPair.fromSerializer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ 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";

public static final String CACHE_PROVIDER_REDIS = "Redis";
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.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>${github-api.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.eclipse.xpanse.modules.deployment;

import static org.eclipse.xpanse.modules.async.TaskConfiguration.ASYNC_EXECUTOR_NAME;
import static org.eclipse.xpanse.modules.logging.LoggingKeyConstant.SERVICE_ID;

import jakarta.annotation.Resource;
Expand Down Expand Up @@ -104,7 +105,7 @@ public class DeployService {
private ServiceOrderManager serviceOrderManager;
@Resource
private ServiceDeploymentStatusChangePolling serviceDeploymentStatusChangePolling;
@Resource
@Resource(name = ASYNC_EXECUTOR_NAME)
private Executor taskExecutor;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.eclipse.xpanse.modules.deployment;

import static org.eclipse.xpanse.modules.async.TaskConfiguration.ASYNC_EXECUTOR_NAME;
import static org.eclipse.xpanse.modules.security.common.RoleConstants.ROLE_ADMIN;

import jakarta.annotation.Resource;
Expand Down Expand Up @@ -49,7 +50,7 @@ public class ServiceOrderManager {
private UserServiceHelper userServiceHelper;
@Resource
private ServiceOrderStatusChangePolling serviceOrderStatusChangePolling;
@Resource
@Resource(name = ASYNC_EXECUTOR_NAME)
private Executor taskExecutor;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.eclipse.xpanse.modules.deployment;

import static org.eclipse.xpanse.modules.async.TaskConfiguration.ASYNC_EXECUTOR_NAME;
import static org.eclipse.xpanse.modules.security.common.RoleConstants.ROLE_ADMIN;

import jakarta.annotation.Resource;
Expand Down Expand Up @@ -35,7 +36,6 @@
import org.eclipse.xpanse.modules.orchestrator.PluginManager;
import org.eclipse.xpanse.modules.orchestrator.servicestate.ServiceStateManageRequest;
import org.eclipse.xpanse.modules.security.UserServiceHelper;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
Expand All @@ -57,8 +57,7 @@ public class ServiceStateManager {
private DatabaseServiceStateManagementTaskStorage taskStorage;
@Resource
private DatabaseDeployServiceStorage deployServiceStorage;
@Qualifier("xpanseAsyncTaskExecutor")
@Resource
@Resource(name = ASYNC_EXECUTOR_NAME)
private Executor taskExecutor;

/**
Expand Down
Loading
Loading