// Ship a container to the warehouse for continuous deployment
Ship a container to the warehouse for continuous deployment
// Ship a container to the warehouse for continuous deployment
func (d *Dispatcher) _shipContainerImageToTruck(containerID, truckID string) uint {
	container, ok := d.Config.Containers[containerID]
	if !ok {
		fmt.Println("Could not find container with ID", containerID)
		return FedopsError
	}
	truck, ok := d.Config.Trucks[truckID]
	if !ok {
		fmt.Println("Could not find truck with ID", truckID)
		return FedopsError
	}
	for i := range container.Trucks {
		if truckID == container.Trucks[i] {
			fmt.Println("Truck with ID", truckID, "has already been set for container", containerID)
			return FedopsError
		}
	}
	auth, err := bcrypt.GenerateFromPassword([]byte(d.Config.ClusterID), AuthorizationCost)
	if err != nil {
		fmt.Println(err.Error())
		return FedopsError
	}
	if container.Warehouse != "" {
		req := fedops_network.FedopsRequest{
			Authorization: auth,
			Method:        fedops_network.FedopsRequestCreate,
			Route:         []byte("/container/" + containerID),
			Data:          []byte("warehouse:" + container.Warehouse),
		}
		conn := d.OpenConnection(truck.IPV4)
		if conn == nil {
			return FedopsError
		}
		err = d.WriteToConn(conn, &req)
		if err != nil {
			fmt.Println(err.Error())
			return FedopsError
		}
		conn.Close()
		req = fedops_network.FedopsRequest{
			Authorization: auth,
			Method:        fedops_network.FedopsRequestCreate,
			Route:         []byte("/container/" + containerID),
			Data:          []byte("truck:" + truckID),
		}
		container.Trucks = append(container.Trucks, truckID)
		warehouse := d.Config.Warehouses[container.Warehouse]
		conn = d.OpenConnection(warehouse.IPV4)
		if conn == nil {
			return FedopsError
		}
		defer conn.Close()
		err = d.WriteToConn(conn, &req)
		if err != nil {
			fmt.Println(err.Error())
			return FedopsError
		}
	} else {
		req := fedops_network.FedopsRequest{
			Authorization: auth,
			Method:        fedops_network.FedopsRequestCreate,
			Route:         []byte("/container/" + containerID),
		}
		conn := d.OpenConnection(truck.IPV4)
		if conn == nil {
			return FedopsError
		}
		defer conn.Close()
		err = d.WriteToConn(conn, &req)
		if err != nil {
			fmt.Println(err.Error())
			return FedopsError
		}
		container.Trucks = append(container.Trucks, truckID)
	}
	return FedopsOk
}
func ( d * Dispatcher ) _shipContainerImageToTruck ( containerID , truckID string ) uint { container , ok := d . Config . Containers [ containerID ] if ! ok { fmt . Println ( " " , containerID ) return FedopsError } truck , ok := d . Config . Trucks [ truckID ] if ! ok { fmt . Println ( " " , truckID ) return FedopsError } for i := range container . Trucks { if truckID == container . Trucks [ i ] { fmt . Println ( " " , truckID , " " , containerID ) return FedopsError } } auth , err := bcrypt . GenerateFromPassword ( [ ] byte ( d . Config . ClusterID ) , AuthorizationCost ) if err != nil { fmt . Println ( err . Error ( ) ) return FedopsError } if container . Warehouse != " " { req := fedops_network . FedopsRequest { Authorization : auth , Method : fedops_network . FedopsRequestCreate , Route : [ ] byte ( " " + containerID ) , Data : [ ] byte ( " " + container . Warehouse ) , } conn := d . OpenConnection ( truck . IPV4 ) if conn == nil { return FedopsError } err = d . WriteToConn ( conn , & req ) if err != nil { fmt . Println ( err . Error ( ) ) return FedopsError } conn . Close ( ) req = fedops_network . FedopsRequest { Authorization : auth , Method : fedops_network . FedopsRequestCreate , Route : [ ] byte ( " " + containerID ) , Data : [ ] byte ( " " + truckID ) , } container . Trucks = append ( container . Trucks , truckID ) warehouse := d . Config . Warehouses [ container . Warehouse ] conn = d . OpenConnection ( warehouse . IPV4 ) if conn == nil { return FedopsError } defer conn . Close ( ) err = d . WriteToConn ( conn , & req ) if err != nil { fmt . Println ( err . Error ( ) ) return FedopsError } } else { req := fedops_network . FedopsRequest { Authorization : auth , Method : fedops_network . FedopsRequestCreate , Route : [ ] byte ( " " + containerID ) , } conn := d . OpenConnection ( truck . IPV4 ) if conn == nil { return FedopsError } defer conn . Close ( ) err = d . WriteToConn ( conn , & req ) if err != nil { fmt . Println ( err . Error ( ) ) return FedopsError } container . Trucks = append ( container . Trucks , truckID ) } return FedopsOk }
Ship a container to the warehouse for continuous deployment
Ship a container to the warehouse for continuous deployment
// Find the state of this container // Does it already have a warehouse // Update the warehouse