refactor(cloudcontrol): move library usages to imports (#3902)

* refactor(cloudcontrol): move library usages to imports

* refactor(cloudcontrol): eliminate var declarations and add explicit type imports
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-09-20 21:16:51 -05:00
1 parent 7777a97de9
commit 44fa114483
3 files changed
+46 -31

No files matched your search

@@ -1,22 +1,22 @@
package io.github.hectorvent.floci.services.cloudcontrol;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationResourceProvisioner;
import io.quarkus.runtime.annotations.RegisterForReflection;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.model.GroupIdentifier;
import io.github.hectorvent.floci.services.ec2.model.Instance;
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
import io.github.hectorvent.floci.services.ec2.model.Reservation;
import io.github.hectorvent.floci.services.iam.model.InstanceProfile;
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
import io.github.hectorvent.floci.services.ec2.model.Subnet;
import io.github.hectorvent.floci.services.ec2.model.Tag;
@@ -24,8 +24,11 @@ import io.github.hectorvent.floci.services.ec2.model.Vpc;
import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.iam.model.IamRole;
import io.github.hectorvent.floci.services.iam.model.IamUser;
import io.github.hectorvent.floci.services.iam.model.InstanceProfile;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.s3.model.Bucket;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -33,8 +36,12 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ApplicationScoped
public class CloudControlService {
@@ -56,24 +63,24 @@ public class CloudControlService {
* properties, a nodegroup's cluster name, an inline policy's principals. Deleting one of these
* from type and identifier alone is a no-op, so Cloud Control must not report SUCCESS for it.
*/
private static final java.util.Set<String> ATTRIBUTE_BACKED_DELETES =
java.util.Set.of("AWS::EKS::Nodegroup", "AWS::IAM::Policy");
private static final Set<String> ATTRIBUTE_BACKED_DELETES =
Set.of("AWS::EKS::Nodegroup", "AWS::IAM::Policy");
/** RequestToken → ProgressEvent. Cloud Control is async; clients poll by token. */
private final Map<String, ProgressEvent> requests = new ConcurrentHashMap<>();
/** Token insertion order, so the map can be bounded without losing in-flight requests. */
private final java.util.concurrent.ConcurrentLinkedQueue<String> requestOrder =
new java.util.concurrent.ConcurrentLinkedQueue<>();
private final ConcurrentLinkedQueue<String> requestOrder =
new ConcurrentLinkedQueue<>();
/**
* What CreateResource provisioned, keyed by region/type/identifier. Carries the attributes the
* delete path needs and the model the read path returns for types outside {@link #listResources}.
* Entries are dropped when the resource is deleted.
*/
private final Map<String, CreatedResource> created = new ConcurrentHashMap<>();
private final java.util.concurrent.ExecutorService executor =
java.util.concurrent.Executors.newFixedThreadPool(4);
private final ExecutorService executor =
Executors.newFixedThreadPool(4);
@jakarta.annotation.PreDestroy
@PreDestroy
void shutdown() {
executor.shutdownNow();
}
@@ -250,7 +257,7 @@ public class CloudControlService {
persistRequest(new PersistedRequest(pending, region, desiredStateJson, System.currentTimeMillis()));
executor.submit(() -> RequestScopes.runAs(accountId, () -> {
try {
var resource = provisioner.provisionStandalone(typeName, props, region, accountId);
StackResource resource = provisioner.provisionStandalone(typeName, props, region, accountId);
if (resource == null || resource.getPhysicalId() == null) {
record(pending.failed("CreateResource is not supported for " + typeName + "."));
} else {
@@ -501,7 +508,7 @@ public class CloudControlService {
putIfPresent(properties, "State", instance.getState().getName());
}
if (instance.getSecurityGroups() != null && !instance.getSecurityGroups().isEmpty()) {
var groups = properties.putArray("SecurityGroupIds");
ArrayNode groups = properties.putArray("SecurityGroupIds");
for (GroupIdentifier g : instance.getSecurityGroups()) {
if (g.getGroupId() != null) groups.add(g.getGroupId());
}
@@ -636,7 +643,7 @@ public class CloudControlService {
if (validTags.isEmpty()) {
return;
}
var tagArray = properties.putArray("Tags");
ArrayNode tagArray = properties.putArray("Tags");
for (Tag tag : validTags) {
tagArray.addObject()
.put("Key", tag.getKey())