def _onData(self, interest, data): print 'in onData' payload = data.getContent() dataName = data.getName() dataName_size = dataName.size() print "Received data name: ", dataName.toUri() data_name_components = dataName.toUri().split("/") if "service_deployment_pull" in data_name_components: fileName = data_name_components[ data_name_components.index("service_deployment_pull") + 1] rel_path = "SEG_repository" abs_path = os.path.join(self.script_dir, rel_path) print "path of SEG_repository:%s" % abs_path print "Service File name:%s" % fileName file_path = os.path.join(abs_path, fileName) dataSegmentNum = (dataName.get(dataName_size - 1)).toSegment() lastSegmentNum = (data.getMetaInfo().getFinalBlockId()).toNumber() print "dataSegmentNum" + str(dataSegmentNum) print "lastSegmentNum" + str(lastSegmentNum) if dataSegmentNum == 0: print 'Start counting received chunks' self.StartCountingReceivedChunks(dataSegmentNum, lastSegmentNum + 1) else: self.UpdatingReceivedChunks(dataSegmentNum) if self.request_SubsequenceDataChunk(abs_path, fileName, data, self.window) == True: timestamp_file = fileName + '.txt' self.StopTimeStamp_MigrationTime(timestamp_file) print 'Load image and run service' if dockerctl.has_ServiceInfo(fileName) == True: print 'Has description for service deployment' ExecutionType = dockerctl.get_ExecutionType(fileName) if ExecutionType == 'singleWebContainer': print 'Deployment uses dockerctl' if dockerctl.deployContainer( fileName, self.num_deployedContainer) == 'error': print 'Image:%s cannot be deployed' % fileName elif ExecutionType == 'DockerCompose': dockerctl.run_DockerCompose_source(fileName) elif ExecutionType == 'kebapp': if dockerctl.deployKEBAPP(fileName) == True: print 'Running docker image %s ...' % fileName else: print 'Error: Cannot run image %s' % fileName else: print 'Execution method is not yet implemented' else: print "function is not yet ready" currentInterestName = interest.getName() # Delete the Interest name from outstanding INTEREST dict as reply DATA has been received. del self.outstanding[currentInterestName.toUri()]
def onInterest_pushService(self, prefix, interest, face, interestFilterId, filter): interestName = interest.getName() ### Delete image_file in SEG_Repe. This is just for migration cost experiment. delete_service_command = 'rm ' + self.repo_path + '*' os.system(delete_service_command) print "Interest Name: %s" % interestName interest_name_components = interestName.toUri().split("/") if "service_deployment_push" in interest_name_components: image_fileName = interest_name_components[ interest_name_components.index("service_deployment_push") + 2] print 'Deploy service: %s' % image_fileName print 'Start service deployment' if dockerctl.has_ServiceInfo(image_fileName) == True: print 'Has description for service deployment' ExecutionType = dockerctl.get_ExecutionType(image_fileName) if ExecutionType == 'singleWebContainer': print 'Deployment uses dockerctl' deployment_status = dockerctl.deployContainer( image_fileName, self.num_deployedContainer) if deployment_status == 'pull_image': print 'Service: %s is not locally cached, pull from Repo' % image_fileName prefix_pullImage = Name( "/picasso/service_deployment_pull/" + image_fileName) print 'Sending Interest message: %s' % prefix_pullImage self._sendNextInterest(prefix_pullImage, self.interestLifetime, 'pull') filename = image_fileName + '.txt' self.StartTimeStamp_MigrationTime(filename) elif deployment_status == 'done': print 'Service:%s is successfully deployed' % image_fileName self.num_deployedContainer += 1 elif deployment_status == 'error': print 'Error in deployment process' else: print 'Code bug' elif ExecutionType == 'DockerCompose': print 'Deployment uses docker compose' if dockerctl.has_imagefile(image_fileName) == True: print 'Load image and run service' dockerctl.run_DockerCompose_source(image_fileName) else: print 'Service: %s is not locally cached, pull from Repo' % image_fileName prefix_pullImage = Name( "/picasso/service_deployment_pull/" + image_fileName) print 'Sending Interest message: %s' % prefix_pullImage self._sendNextInterest(prefix_pullImage, self.interestLifetime, 'pull') timestamp_file = image_fileName + '.txt' self.StartTimeStamp_MigrationTime(timestamp_file) else: print 'Execution method is not yet implemented' else: print 'Deployment description is not available' else: print "Interest name mismatch"