Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public class OpenStack4JDriver extends VimDriver {
private Logger log = LoggerFactory.getLogger(OpenStack4JDriver.class);
private static Lock lock;

//This map should be implemented using VimInstance as key, but it needs to override VimInstance::hashCode()
//Using VimInstance as key ensures that a new OSClient will be created and cached when password or other attributes change
//MAP <Id VIM , client>
private HashMap<String, OSClient> osCache = new HashMap<String, OSClient>();

public OpenStack4JDriver() {
super();
init();
Expand All @@ -92,7 +97,13 @@ public void init() {

public OSClient authenticate(VimInstance vimInstance) throws VimDriverException {

OSClient os;
//OSClient os;
OSClient os = osCache.get(vimInstance.getId());
if (os != null) {
log.debug("Returning cached osClient...");
return os;
}

try {
if (isV3API(vimInstance)) {

Expand Down Expand Up @@ -125,6 +136,8 @@ public OSClient authenticate(VimInstance vimInstance) throws VimDriverException
"Not found region '"
+ vimInstance.getLocation().getName()
+ "'. Use default one...");
osCache.put(vimInstance.getId(), os);
log.debug("saved new osClient in cache");
return os;
}
}
Expand Down Expand Up @@ -153,6 +166,8 @@ public OSClient authenticate(VimInstance vimInstance) throws VimDriverException
} catch (AuthenticationException e) {
throw new VimDriverException(e.getMessage(), e);
}
osCache.put(vimInstance.getId(), os);
log.debug("saved new osClient in cache");
return os;
}

Expand Down Expand Up @@ -580,7 +595,8 @@ public Server launchInstanceAndWait(
server.setFloatingIps(new HashMap<String, String>());
}
if (floatingIps != null && floatingIps.size() > 0) {
OpenStack4JDriver.lock.lock(); // TODO chooseFloating ip is lock but association is parallel
OpenStack4JDriver.lock
.lock(); // TODO chooseFloating ip is lock but association is parallel
log.debug("Assigning FloatingIPs to VM with hostname: " + name);
log.debug("FloatingIPs are: " + floatingIps);
int freeIps = listFloatingIps(this.authenticate(vimInstance), vimInstance).size();
Expand Down