starting implementation of admiralty annotations
This commit is contained in:
		| @@ -184,7 +184,8 @@ func (b *ArgoBuilder) createArgoTemplates(id string, | ||||
| 	_, firstItems, lastItems = b.addTaskToArgo(b.Workflow.getDag(), id, processing, firstItems, lastItems) | ||||
| 	template := &Template{Name: getArgoName(processing.GetName(), id)} | ||||
| 	fmt.Println("Creating template for", template.Name) | ||||
| 	template.CreateContainer(processing, b.Workflow.getDag()) | ||||
| 	isReparted, url := b.isProcessingReparted(*processing) | ||||
| 	template.CreateContainer(processing, b.Workflow.getDag(), isReparted, url) | ||||
| 	// get datacenter from the processing | ||||
| 	if processing.IsService { | ||||
| 		b.CreateService(id, processing) | ||||
| @@ -230,6 +231,7 @@ func (b *ArgoBuilder) createArgoTemplates(id string, | ||||
| 	b.Workflow.Spec.Templates = append(b.Workflow.Spec.Templates, *template) | ||||
| 	return volumes, firstItems, lastItems | ||||
| } | ||||
|  | ||||
| func (b *ArgoBuilder) addTaskToArgo(dag *Dag, graphItemID string, processing *resources.ProcessingResource, | ||||
| 	firstItems []string, lastItems []string) (*Dag, []string, []string) { | ||||
| 	unique_name := getArgoName(processing.GetName(), graphItemID) | ||||
| @@ -332,3 +334,87 @@ func getArgoName(raw_name string, component_id string) (formatedName string) { | ||||
| 	formatedName = strings.ToLower(formatedName) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // Verify if a processing resource is attached to another Compute than the one hosting | ||||
| // the current Open Cloud instance. If true return the URL to contact the remote instance | ||||
| // kube API | ||||
|   | ||||
| func (b *ArgoBuilder) isProcessingReparted(processing resources.ProcessingResource) (bool,string) { | ||||
| 	processCreator := processing.CreatorID | ||||
| 	// Creates an accessor srtictly for Peer Collection  | ||||
| 	req := oclib.NewRequest(oclib.LibDataEnum(oclib.PEER),"","",nil,nil) | ||||
| 	if req == nil { | ||||
| 		fmt.Println("TODO : handle error when trying to create a request on the Peer Collection") | ||||
| 		return false, "" | ||||
| 	}  | ||||
|  | ||||
| 	res := req.LoadOne(processCreator) | ||||
| 	if res.Err != "" { | ||||
| 		fmt.Print("TODO : handle error when requesting PeerID") | ||||
| 		fmt.Print(res.Err) | ||||
| 		return false, "" | ||||
| 	} | ||||
| 	 | ||||
| 	peer := res.ToPeer() | ||||
| 	if peer == nil { | ||||
| 		fmt.Print("TODO : handle error when converting PeerID") | ||||
| 	} | ||||
|  | ||||
| 	isReparted, _ := peer.IsMySelf() | ||||
| 	if isReparted { | ||||
| 		remoteCompute := b.retrieveProcessingCompute(processing) | ||||
| 		computeInstance := remoteCompute.GetSelectedInstance() | ||||
| 		if computeInstance == nil { | ||||
| 			fmt.Println("TODO: handle when retrieving instance") | ||||
| 			return false, "" | ||||
| 		} | ||||
|  | ||||
| 		instance := computeInstance.(*resources.ComputeResourceInstance) | ||||
| 		return true, instance.Source | ||||
| 	} | ||||
| 	 | ||||
| 	return false, "" | ||||
| } | ||||
|  | ||||
| func (b *ArgoBuilder) retrieveProcessingCompute(processing resources.ProcessingResource) *resources.ComputeResource { | ||||
| 	for _, link := range b.OriginWorkflow.Graph.Links { | ||||
| 		// If a link contains the id of the processing | ||||
| 		var oppositeId string  | ||||
| 		if link.Source.ID == processing.AbstractResource.UUID{ | ||||
| 			oppositeId = link.Destination.ID | ||||
| 		} else if(link.Destination.ID == processing.AbstractResource.UUID){ | ||||
| 			oppositeId = link.Source.ID | ||||
| 		} | ||||
|  | ||||
| 		if oppositeId != "" { | ||||
| 			isCompute, object := isCompute(oppositeId) | ||||
| 			if !isCompute { | ||||
| 				continue | ||||
| 			} | ||||
| 			return object | ||||
| 		} | ||||
|  | ||||
| 	} | ||||
| 		 | ||||
| 	return nil  | ||||
| } | ||||
|  | ||||
| func isCompute(resourceId string) (bool, *resources.ComputeResource) { | ||||
| 	req := oclib.NewRequest(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),"","",nil,nil) | ||||
| 	if req == nil { | ||||
| 		fmt.Print("TODO : handle error when creating a NewRequest()") | ||||
| 		return false, nil | ||||
| 	} | ||||
| 	res := req.LoadOne(resourceId) | ||||
| 		 | ||||
| 	if res.Err != "" { | ||||
| 		return false, nil | ||||
| 	} | ||||
| 	 | ||||
| 	compute := res.ToComputeResource() | ||||
| 	if compute == nil {	// Maybe we should add an Err returned by ToXXXXResource()  | ||||
| 		return false, nil | ||||
| 	}			 | ||||
|  | ||||
| 	return true, compute | ||||
| } | ||||
		Reference in New Issue
	
	Block a user