Skip to content

Commit

Permalink
Merge pull request #283 from brunoasr/brunoasr/ami_volume_size_filter
Browse files Browse the repository at this point in the history
Dynamic AMI selection: fix architecture filter
  • Loading branch information
vahidhashemian authored Jul 30, 2024
2 parents 6b0ed39 + 3d9360f commit bc90bfc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import software.amazon.awssdk.services.ec2.model.CreateTagsRequest;
import software.amazon.awssdk.services.ec2.model.CreateTagsResponse;
import software.amazon.awssdk.services.ec2.model.Filter;
import software.amazon.awssdk.services.ec2.model.Image;
import software.amazon.awssdk.services.ec2.model.Tag;

/**
Expand All @@ -50,7 +49,7 @@ public class AmiTagManager {
public static final String KEY_AMI_ID = "ami_id";
public static final String KEY_APPLICATION = "application";
public static final String KEY_RELEASE = "release";
public static final String KEY_CPU_ARCHITECTURE = "cpu_architecture";
public static final String KEY_ARCHITECTURE = "architecture";
public static final String KEY_APPLICATION_ENVIRONMENT = "application_environment";
public static final String VALUE_KAFKA = "kafka";
public static UnaryOperator<String> tag = key -> "tag:" + key;
Expand Down Expand Up @@ -82,10 +81,10 @@ public List<Ami> getAmiList(Map<String, String> filter) {
.values(filter.get(KEY_RELEASE))
.build()
);
if (filter.containsKey(KEY_CPU_ARCHITECTURE))
if (filter.containsKey(KEY_ARCHITECTURE))
filterList.add(
filterBuilder.name(tag.apply(KEY_CPU_ARCHITECTURE))
.values(filter.get(KEY_CPU_ARCHITECTURE))
filterBuilder.name(KEY_ARCHITECTURE)
.values(filter.get(KEY_ARCHITECTURE))
.build()
);
filterList.add(
Expand All @@ -98,7 +97,7 @@ public List<Ami> getAmiList(Map<String, String> filter) {
DescribeImagesResponse resp = ec2Client.describeImages(builder.build());
if (resp.hasImages() && !resp.images().isEmpty()) {
// The limitation of images newer than 180 days is temporarily suspended
//ZonedDateTime cutDate = ZonedDateTime.now().minusDays(180);
// ZonedDateTime cutDate = ZonedDateTime.now().minusDays(180);
resp.images().forEach(image -> {
/*if (ZonedDateTime.parse(image.creationDate(), DateTimeFormatter.ISO_ZONED_DATE_TIME).isAfter(cutDate)) {*/
Iterator<Tag> i = image.tags().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Ami {
*
* @param amiId - for AWS, the string "ami-" and a sequence of 17 characters
* @param applicationEnvironment - comma-separated list of environments (dev, test,
* staging, prod) supported by this ami
* stage, prod, m10n) supported by this ami
* @param creationDate - ami creation date, UTC
* @return the new Ami instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ public Map<String, Map<String, Utilization>> getUtilizationDetailsByCluster() {
@GET
public List<Ami> describeImages(
@QueryParam(AmiTagManager.KEY_RELEASE) String os,
@QueryParam(AmiTagManager.KEY_CPU_ARCHITECTURE) String arch
@QueryParam(AmiTagManager.KEY_ARCHITECTURE) String arch
) {
Map<String, String> filter = new HashMap<>();
if (os != null)
filter.put(AmiTagManager.KEY_RELEASE, os);
if (arch != null)
filter.put(AmiTagManager.KEY_CPU_ARCHITECTURE, arch);
filter.put(AmiTagManager.KEY_ARCHITECTURE, arch);
if (amiTagManager == null)
amiTagManager = new AmiTagManager();
return amiTagManager.getAmiList(filter);
Expand Down
35 changes: 19 additions & 16 deletions orion-server/src/main/resources/webapp/src/basic-components/Ami.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,30 @@ function Ami({ amiList, requestAmiList, envTypes, requestEnvTypes, updateAmiTag
const handleOSChange = event => {
setOS(event.target.value);
};
const [cpuArch, setCPUArch] = React.useState();
const handleCPUArchChange = event => {
setCPUArch(event.target.value);
const [arch, setArch] = React.useState();
const handleArchChange = event => {
setArch(event.target.value);
};
const [selected, setSelected] = React.useState([]);
const [env, setEnv] = React.useState({});
if (envTypes !== undefined && Object.keys(env).length == 0) {
const targetEnv = {};
envTypes.forEach(value => { targetEnv[value] = false; });
setEnv(targetEnv);
}
const handleTableRowSelect = (id, row) => {
setSelected(id);
setAppEnv(row.applicationEnvironment);
const envs_str = row.applicationEnvironment;
const envs = envs_str.split(',');
env.dev = env.test = env.staging = env.prod = false;
envTypes.forEach(envType => { env[envType] = false; });
for (const env_str of envs)
env[env_str] = true;
};
const [appEnv, setAppEnv] = React.useState();
const handleAppEnvChange = event => {
setAppEnv(event.target.value);
};
const envMap = {};
if (envTypes !== undefined)
envTypes.forEach(value => { envMap[value] = false; });
const [env] = React.useState(envMap);
const handleCheckboxChange = (event) => {
env[event.target.name] = event.target.checked;
const newAppEnv = [];
Expand All @@ -81,8 +83,8 @@ function Ami({ amiList, requestAmiList, envTypes, requestEnvTypes, updateAmiTag
const parms = [];
if (os)
parms.push("release=" + os);
if (cpuArch)
parms.push("cpu_architecture=" + cpuArch);
if (arch)
parms.push("architecture=" + arch);
requestAmiList(parms.join('&'));
requestEnvTypes();
}
Expand Down Expand Up @@ -121,20 +123,21 @@ function Ami({ amiList, requestAmiList, envTypes, requestEnvTypes, updateAmiTag
>
<MenuItem value={"bionic"}>bionic</MenuItem>
<MenuItem value={"focal"}>focal</MenuItem>
<MenuItem value={"noble"}>noble</MenuItem>
</Select>
</FormControl>
</div>
<div>
<FormControl className={classes.formControl}>
<InputLabel id="lblCPUArch">CPU Architecture</InputLabel>
<InputLabel id="lblArch">architecture</InputLabel>
<Select
labelId="lblSelectCPUArch"
id="selectCPUArch"
value={cpuArch}
onChange={handleCPUArchChange}
labelId="lblSelectArch"
id="selectArch"
value={arch}
onChange={handleArchChange}
style={{ width: "200px", textAlign: "left" }}
>
<MenuItem value={"amd64"}>amd64</MenuItem>
<MenuItem value={"x86_64"}>x86_64</MenuItem>
<MenuItem value={"arm64"}>arm64</MenuItem>
</Select>
</FormControl>
Expand Down

0 comments on commit bc90bfc

Please sign in to comment.