// 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) _shipContainerToWarehouse(containerID, warehouseID string) uint {
	container, ok := d.Config.Containers[containerID]
	if !ok {
		fmt.Println("Could not find container with ID", containerID)
		return FedopsError
	}
	warehouse, ok := d.Config.Warehouses[warehouseID]
	if !ok {
		fmt.Println("Could not find warehouse with ID", warehouseID)
		return FedopsError
	}
	if warehouseID == container.Warehouse {
		fmt.Println("Warehouse with ID", warehouseID, "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 len(container.Trucks) > 0 {
		for key := range container.Trucks {
			truck := d.Config.Trucks[container.Trucks[key]]
			req := fedops_network.FedopsRequest{
				Authorization: auth,
				Method:        fedops_network.FedopsRequestUpdate,
				Route:         []byte("/container/" + containerID),
				Data:          []byte("truck:" + container.Trucks[key]),
			}
			conn := d.OpenConnection(warehouse.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("warehouse:" + warehouseID),
			}
			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()
		}
		container.Warehouse = warehouseID
	} else {
		req := fedops_network.FedopsRequest{
			Authorization: auth,
			Method:        fedops_network.FedopsRequestCreate,
			Route:         []byte("/container/" + containerID),
		}
		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
		}
		container.Warehouse = warehouseID
	}
	return FedopsOk
}
func ( d * Dispatcher ) _shipContainerToWarehouse ( containerID , warehouseID string ) uint { container , ok := d . Config . Containers [ containerID ] if ! ok { fmt . Println ( " " , containerID ) return FedopsError } warehouse , ok := d . Config . Warehouses [ warehouseID ] if ! ok { fmt . Println ( " " , warehouseID ) return FedopsError } if warehouseID == container . Warehouse { fmt . Println ( " " , warehouseID , " " , containerID ) return FedopsError } auth , err := bcrypt . GenerateFromPassword ( [ ] byte ( d . Config . ClusterID ) , AuthorizationCost ) if err != nil { fmt . Println ( err . Error ( ) ) return FedopsError } if len ( container . Trucks ) > 0 { for key := range container . Trucks { truck := d . Config . Trucks [ container . Trucks [ key ] ] req := fedops_network . FedopsRequest { Authorization : auth , Method : fedops_network . FedopsRequestUpdate , Route : [ ] byte ( " " + containerID ) , Data : [ ] byte ( " " + container . Trucks [ key ] ) , } conn := d . OpenConnection ( warehouse . 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 ( " " + warehouseID ) , } 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 ( ) } container . Warehouse = warehouseID } else { req := fedops_network . FedopsRequest { Authorization : auth , Method : fedops_network . FedopsRequestCreate , Route : [ ] byte ( " " + containerID ) , } 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 } container . Warehouse = warehouseID } 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 any trucks // Update the warehouse