Skip to content

Commit

Permalink
Merge pull request #1511 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer committed Oct 24, 2023
2 parents 7fa9949 + f913a02 commit ab994ce
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions IM/connectors/Lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import threading
import os
import re
import yaml
Expand All @@ -36,6 +37,8 @@ class LambdaCloudConnector(CloudConnector):
Cloud Launcher to create Lambda functions.
"""

_lock = threading.Lock()
"""Threading Lock to avoid concurrency problems."""
type = "Lambda"
"""str with the name of the provider."""

Expand Down Expand Up @@ -173,9 +176,10 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
inf.add_vm(vm)

try:
self._set_scar_env(radl.systems[0], auth_data)
AWS("init")
self._free_scar_env()
with LambdaCloudConnector._lock:
self._set_scar_env(radl.systems[0], auth_data)
AWS("init")
self._free_scar_env()
vm.destroy = False
vm.state = VirtualMachine.RUNNING
res.append((True, vm))
Expand All @@ -191,10 +195,11 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):

def finalize(self, vm, last, auth_data):
try:
aws_resources = self._set_scar_env(vm.info.systems[0], auth_data)
Lambda(aws_resources["functions"]["aws"][0]).get_function_configuration(vm.id)
AWS("rm")
self._free_scar_env()
with LambdaCloudConnector._lock:
aws_resources = self._set_scar_env(vm.info.systems[0], auth_data)
Lambda(aws_resources["functions"]["aws"][0]).get_function_configuration(vm.id)
AWS("rm")
self._free_scar_env()
except ClientError as ce:
# Function not found
if ce.response['Error']['Code'] == 'ResourceNotFoundException':
Expand Down Expand Up @@ -224,10 +229,11 @@ def update_system_info_from_function_conf(system, func_conf):

def updateVMInfo(self, vm, auth_data):
try:
aws_resources = self._set_scar_env(vm.info.systems[0], auth_data)
func_conf = Lambda(aws_resources["functions"]["aws"][0]).get_function_configuration(vm.id)
self.update_system_info_from_function_conf(vm.info.systems[0], func_conf)
self._free_scar_env()
with LambdaCloudConnector._lock:
aws_resources = self._set_scar_env(vm.info.systems[0], auth_data)
func_conf = Lambda(aws_resources["functions"]["aws"][0]).get_function_configuration(vm.id)
self.update_system_info_from_function_conf(vm.info.systems[0], func_conf)
self._free_scar_env()
return True, vm
except ClientError as ce:
# Function not found
Expand All @@ -250,11 +256,12 @@ def alterVM(self, vm, radl, auth_data):

if new_memory and new_memory != memory:
try:
aws_resources = self._set_scar_env(vm.info.systems[0], auth_data)
Lambda(aws_resources["functions"]["aws"][0]).client.update_function_configuration(
MemorySize=new_memory, FunctionName=vm.id)
self.update_system_info_from_function_conf(vm.info.systems[0], {"MemorySize": new_memory})
self._free_scar_env()
with LambdaCloudConnector._lock:
aws_resources = self._set_scar_env(vm.info.systems[0], auth_data)
Lambda(aws_resources["functions"]["aws"][0]).client.update_function_configuration(
MemorySize=new_memory, FunctionName=vm.id)
self.update_system_info_from_function_conf(vm.info.systems[0], {"MemorySize": new_memory})
self._free_scar_env()
return True, vm
except ClientError as ce:
# Function not found
Expand Down

0 comments on commit ab994ce

Please sign in to comment.