Commit fd8fce05 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Improve jclouds handled instance types synchronization with node candidates retrieval

parent e887fed9
......@@ -46,6 +46,7 @@ dependencies {
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-csv', version: '2.12.1'
compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.common', version: '2.20.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile group: 'org.apache.jclouds.api', name: 'ec2', version: '2.2.1'
annotationProcessor "org.projectlombok:lombok:1.18.12"
compile 'org.junit.jupiter:junit-jupiter:5.6.2'
testImplementation 'org.mockito:mockito-inline:3.7.7'
......
......@@ -101,6 +101,12 @@
<version>3.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.api</groupId>
<artifactId>ec2</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -5,10 +5,7 @@ import org.activeeon.morphemic.application.deployment.PASchedulerGateway;
import org.activeeon.morphemic.infrastructure.deployment.PAConnectorIaasGateway;
import org.activeeon.morphemic.infrastructure.deployment.PAResourceManagerGateway;
import org.activeeon.morphemic.model.*;
import org.activeeon.morphemic.service.EntityManagerHelper;
import org.activeeon.morphemic.service.NodeCandidateUtils;
import org.activeeon.morphemic.service.TemporaryFilesHelper;
import org.activeeon.morphemic.service.UpdatingNodeCandidatesThread;
import org.activeeon.morphemic.service.*;
import org.apache.commons.lang3.Validate;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
......@@ -285,11 +282,11 @@ public class PAGateway {
List<NodeCandidate> allNodeCandidates = EntityManagerHelper.createQuery("SELECT nc FROM NodeCandidate nc",
NodeCandidate.class).getResultList();
allNodeCandidates.forEach(nodeCandidate -> {
// Hardware types t3a and t4g are not YET, handled by jclouds.
if (NodeCandidateUtils.verifyAllFilters(requirements, nodeCandidate) &&
!nodeCandidate.getHardware().getName().startsWith("t3a") &&
!nodeCandidate.getHardware().getName().startsWith("t4g")) {
filteredNodeCandidates.add(nodeCandidate);
if (JCloudsInstancesUtils.isHandledHardwareInstanceType(nodeCandidate.getCloud().getApi().getProviderName(),
nodeCandidate.getHardware().getName())) {
if (NodeCandidateUtils.verifyAllFilters(requirements, nodeCandidate)) {
filteredNodeCandidates.add(nodeCandidate);
}
}
});
return filteredNodeCandidates;
......
package org.activeeon.morphemic.service;
import org.apache.log4j.Logger;
import org.jclouds.ec2.domain.InstanceType;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class JCloudsInstancesUtils {
private static final Set<String> handledAWSInstanceTypes;
private static final Logger LOGGER = Logger.getLogger(JCloudsInstancesUtils.class);
static {
handledAWSInstanceTypes = new HashSet<>();
Arrays.stream(InstanceType.class.getFields()).forEach(field -> {
try {
handledAWSInstanceTypes.add(field.get(InstanceType.class).toString());
} catch (IllegalAccessException e) {
LOGGER.warn(e.getStackTrace());
}
});
}
private JCloudsInstancesUtils() {
}
/**
* Some hardware instance types (like t3a and t4g for AWS) are not YET, handled by jclouds.
* This method is here to check if the instance type is handled or not.
* @param providerName The Cloud provider id
* @param instanceType The instance type to be checked
* @return true if the instance type is handled by jclouds, false otherwise
*/
public static boolean isHandledHardwareInstanceType(String providerName, String instanceType) {
if ("aws-ec2".equals(providerName))
return handledAWSInstanceTypes.contains(instanceType);
// TODO: To check if for other cloud providers all instance types are handled by JClouds
return true;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment