dev

package
v3.2.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2020 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_BASE_OS_VALUE = "alpine:latest"
View Source
const DEFAULT_DEPENDENCY_DIR = "dependencies"
View Source
const DEFAULT_DEVTOOL_HZN_FSS_WORKING_DIR = "/tmp/hzndev/"
View Source
const DEFAULT_GLOBALSET_TYPE = ""
View Source
const DEFAULT_PROP_VALUE = "value1"
View Source
const DEFAULT_SDEF_SPECIFIC_VERSION = "specific_version_number"
View Source
const DEFAULT_SDEF_URL = ""
View Source
const DEFAULT_WORKING_DIR = "horizon"
View Source
const DEFUALT_PROP_NAME = "prop1"
View Source
const DEPENDENCY_COMMAND = "dependency"
View Source
const DEPENDENCY_FETCH_COMMAND = "fetch"
View Source
const DEPENDENCY_GITIGNORE_FILE = "dependencies/.gitignore"
View Source
const DEPENDENCY_GITIGNORE_FILE_CONTENT = `*.service.definition.json
`
View Source
const DEPENDENCY_LIST_COMMAND = "list"
View Source
const DEPENDENCY_REMOVE_COMMAND = "remove"
View Source
const DEVTOOL_HZN_DEVICE_ID = "HZN_DEVICE_ID"
View Source
const DEVTOOL_HZN_EXCHANGE_URL = "HZN_EXCHANGE_URL"
View Source
const DEVTOOL_HZN_FSS_CSS_PORT = "HZN_DEV_FSS_CSS_PORT"
View Source
const DEVTOOL_HZN_FSS_IMAGE_TAG = "HZN_DEV_FSS_IMAGE_TAG"
View Source
const DEVTOOL_HZN_FSS_WORKING_DIR = "HZN_DEV_FSS_WORKING_DIR"
View Source
const DEVTOOL_HZN_ORG = "HZN_ORG_ID"

Constants that hold the name of env vars used with the context of the hzn dev commands.

View Source
const DEVTOOL_HZN_PATTERN = "HZN_PATTERN"
View Source
const DEVTOOL_HZN_USER = "HZN_EXCHANGE_USER_AUTH"
View Source
const DOCKER_FILE = "Dockerfile"
View Source
const DOCKER_FILE_CONTENT = `FROM BASE_OS

COPY *.sh /
WORKDIR /
CMD /service.sh`
View Source
const HORIZON_GITIGNORE_FILE = ".gitignore"
View Source
const HORIZON_GITIGNORE_FILE_CONTENT = `/.hzn.json.tmp.mk
`
View Source
const HZNENV_FILE = "hzn.json"
View Source
const MAKE_FILE = "Makefile"
View Source
const MAKE_FILE_CONTENT = `` /* 1021-byte string literal not displayed */
View Source
const PATTERN_DEFINITION_ALL_ARCHES_FILE = "pattern-all-arches.json"
View Source
const PATTERN_DEFINITION_FILE = "pattern.json"
View Source
const SERVICE_COMMAND = "service"

These constants define the hzn dev subcommands supported by this module.

View Source
const SERVICE_CREATION_COMMAND = "new"
View Source
const SERVICE_DEFINITION_FILE = "service.definition.json"
View Source
const SERVICE_FILE = "service.sh"
View Source
const SERVICE_FILE_CONTENT = `` /* 132-byte string literal not displayed */
View Source
const SERVICE_NEW_DEFAULT_VERSION = "0.0.1"
View Source
const SERVICE_POLICY_FILE = "service.policy.json"
View Source
const SERVICE_START_COMMAND = "start"
View Source
const SERVICE_STOP_COMMAND = "stop"
View Source
const SERVICE_VERIFY_COMMAND = "verify"
View Source
const USERINPUT_FILE = "userinput.json"

Variables

View Source
var BASE_OS_VALUE = map[string]string{"amd64": "alpine:latest", "arm": "arm32v6/alpine:latest", "arm64": "arm64v8/alpine:latest"}

Functions

func AbstractServiceValidation

func AbstractServiceValidation(dir string) error

func AddConfiguredUserInputs

func AddConfiguredUserInputs(configVars map[string]interface{}, envvars map[string]string) error

Convert user input variables and values (for a service) to environment variables and add them to an env var map.

func AddDefaultUserInputs

func AddDefaultUserInputs(uis []exchange.UserInput, envmap map[string]string)

Convert default user inputs to environment variables in a map. The input map is modified by this function. If a variable is already in the input map, it is not modified.

func CommonExecutionSetup

func CommonExecutionSetup(homeDirectory string, userInputFile string, projectType string, cmd string) (string, *register.InputFile, *container.ContainerWorker)

This function is used to setup context to execute a service container.

func CommonProjectValidation

func CommonProjectValidation(dir string, userInputFile string, projectType string, cmd string, userCreds string, autoAddDep bool)

autoAddDep -- if true, the dependent services will be automatically added if they can be found from the exchange

func CreateDependencyGitIgnoreFile

func CreateDependencyGitIgnoreFile(directory string) error

func CreateDockerFiles

func CreateDockerFiles(directory string) error

This function creates 3 Dockerfiles, for amd64, arm and arm64.

func CreateFile

func CreateFile(directory string, fileName string, obj interface{}) error

This function takes one of the project json objects and writes it to a file in the project.

func CreateFileWithConent

func CreateFileWithConent(directory string, filename string, content string, substitutes map[string]string, perm_exec bool) error

check the file existance, substitute the variables and save the file

func CreateHorizonGitIgnoreFile

func CreateHorizonGitIgnoreFile(directory string) error

func CreateHznEnvFile

func CreateHznEnvFile(directory string, org string, specRef string, version string, image_base string) error

It creates a hzn.json file that contains the enviromental variables needed for this project.

func CreateMakeFile

func CreateMakeFile(directory string, hznenv_dir string) error

func CreatePatternDefinition

func CreatePatternDefinition(directory string) error

It creates a pattern definition config object and writes it to the project in the file system.

func CreatePatternDefinitionAllArches

func CreatePatternDefinitionAllArches(directory string) error

It creates a pattern definition config object for all architectures and writes it to the project in the file system.

func CreateServiceDefinition

func CreateServiceDefinition(directory string, specRef string, imageInfo map[string]string, noImageGen bool, deploymentType string) error

Sort of like a constructor, it creates a service definition config object and writes it to the project in the file system.

func CreateServiceFile

func CreateServiceFile(directory string) error

func CreateServiceImageFiles

func CreateServiceImageFiles(directory string, hznenv_dir string) error

It creates a sample Dockerfile for the service container image in the file system. For now we only handle the first image.

func CreateServicePolicy

func CreateServicePolicy(directory string) error

Sort of like a constructor, it creates a service policy object and writes it to the project in the file system.

func CreateSourceCodeManagementFiles

func CreateSourceCodeManagementFiles(directory string) error

It creates gitignore files

func CreateUserInputs

func CreateUserInputs(directory string, specRef string) error

Sort of like a constructor, it creates a user input config object and writes it to the project in the file system.

func CreateWorkingDir

func CreateWorkingDir(dir string) error

Create the working directory if needed.

func DependenciesExists

func DependenciesExists(directory string, okToCreate bool) (bool, error)

Check for the existence of the dependency directory in the project.

func DependencyFetch

func DependencyFetch(homeDirectory string, project string, specRef string, url string, org string, version string, arch string, userCreds string, userInputFile string)

This is the entry point for the hzn dev dependency fetch command.

func DependencyList

func DependencyList(homeDirectory string)

This is the entry point for the hzn dev dependency list command.

func DependencyRemove

func DependencyRemove(homeDirectory string, specRef string, url string, version string, arch string, org string)

This is the entry point for the hzn dev dependency remove command.

func FileExists

func FileExists(directory string, fileName string) (bool, error)

Check for file existence and return any errors.

func FileNotExist

func FileNotExist(dir string, cmd string, fileName string, check func(string) (bool, error))

Check for a file's existence or error out of the command. This is just a way to consolidate the error handling because we have several files that we're dealing with.

func FileValidation

func FileValidation(configFiles []string, configType string, projectType string, cmd string) []string

Validate that the input list of files actually exist.

func GetAbstractDefinition

func GetAbstractDefinition(directory string) (cliexchange.AbstractServiceFile, error)

Sort of like a constructor, it creates an in memory object except that it is created from a service definition config file in the current project. This function assumes the caller has determined the exact location of the file. This function also assumes that the project pointed to by the directory parameter is assumed to contain the kind of definition the caller expects.

func GetDependencyFiles

func GetDependencyFiles(directory string, fileSuffix string) ([]os.FileInfo, error)

Returns an os.FileInfo object for each dependency file. This function assumes the caller has determined the exact location of the files.

func GetDevWorkingDirectory

func GetDevWorkingDirectory() string

func GetFile

func GetFile(directory string, fileName string, obj interface{}) error

This function demarshals the file bytes into the input obj structure. The contents of what obj points to will be modified by this function.

func GetImageInfoFromImageList

func GetImageInfoFromImageList(images []string, version string, noImageGen bool) (map[string]string, string, error)

This function extracts the image names from the image list and returns a map of name~image pairs. If the image does not have version tag specified, this function will add $SERVICE_VERSION as the tag so that it's easy for the user to update the version later. And it will append_$ARCH to the image name so distiguash images from different arch.

func GetNodeId

func GetNodeId() string

func GetPatternDefinition

func GetPatternDefinition(directory string, name string) (*cliexchange.PatternFile, error)

Sort of like a constructor, it creates an in memory object except that it is created from the patern definition config file in the current project. This function assumes the caller has determined the exact location of the file.

func GetServiceDefinition

func GetServiceDefinition(directory string, name string) (*cliexchange.ServiceFile, error)

Sort of like a constructor, it creates an in memory object except that it is created from the service definition config file in the current project. This function assumes the caller has determined the exact location of the file.

func GetServiceDependencies

func GetServiceDependencies(directory string, deps []exchange.ServiceDependency) ([]*cliexchange.ServiceFile, error)

func GetServicePolicy

func GetServicePolicy(directory string, name string) (*cliexchange.ServicePolicyFile, error)

Sort of like a constructor, it creates an in memory object from the service policy file. This function assumes the caller has determined the exact location of the file.

func GetServiceSpecFromImage

func GetServiceSpecFromImage(image string) (string, string, error)

It is used by "hzn dev service new" when the specRef is an empty string. This function generates a service specRef and version from the image name provided by the user.

func GetUserInputs

func GetUserInputs(homeDirectory string, userInputFile string) (*register.InputFile, string, error)

Sort of like a constructor, it creates an in memory object except that it is created from the user input config file in the current project. This function assumes the caller has determined the exact location of the file.

func GetUserInputsVariableConfiguration

func GetUserInputsVariableConfiguration(homeDirectory string, userInputFile string) ([]register.MicroWork, error)

Given a userinput file, extract the configured variables based on the type of project.

func GetWorkingDir

func GetWorkingDir(dashD string, verifyExists bool) (string, error)

The current working directory could be specified via input (as an absolute or relative path) or it could be defaulted if there is no input. If it must exist but does not, return an error.

func GlobalSetAsAttributes

func GlobalSetAsAttributes(global []register.GlobalSet) ([]persistence.Attribute, error)

Convert each attribute in the global set of attributes to a persistent attribute. This enables us to reuse the validation logic and to reuse the logic that converts persistent attributes to environment variables.

func IsServiceProject

func IsServiceProject(directory string) bool

Indicates whether or not the given project is a service project.

func PatternDefinitionAllArchesExists

func PatternDefinitionAllArchesExists(directory string) (bool, error)

Check for the existence of the pattern definition all in one config file in the project.

func PatternDefinitionExists

func PatternDefinitionExists(directory string) (bool, error)

Check for the existence of the pattern definition config file in the project.

func ProcessStartDependencies

func ProcessStartDependencies(dir string, deps []*cliexchange.ServiceFile, globals []register.GlobalSet, configUserInputs []register.MicroWork, cw *container.ContainerWorker) (map[string]docker.ContainerNetwork, error)

func ProcessStopDependencies

func ProcessStopDependencies(dir string, deps []*cliexchange.ServiceFile, cw *container.ContainerWorker) error

func RefreshServiceDependencies

func RefreshServiceDependencies(homeDirectory string, newDepDef cliexchange.AbstractServiceFile) error

Refresh the RequiredServices dependencies in the definition. This is called when new dependencies are added or removed.

func RemoveConfiguredVariables

func RemoveConfiguredVariables(homeDirectory string, theDep cliexchange.AbstractServiceFile) error

Remove configured variables from the userinputs file

func RemoveServiceDependency

func RemoveServiceDependency(homeDirectory string, theDepDef cliexchange.AbstractServiceFile) error

func ServiceDefinitionExists

func ServiceDefinitionExists(directory string) (bool, error)

Check for the existence of the service definition config file in the project.

func ServiceNew

func ServiceNew(homeDirectory string, org string, specRef string, version string, images []string, noImageGen bool, dconfig string, noPattern bool, noPolicy bool)

Create skeletal horizon metadata files to establish a new service project.

func ServicePolicyExists

func ServicePolicyExists(directory string) (bool, error)

Check for the existence of the service policy file in the project.

func ServiceStartTest

func ServiceStartTest(homeDirectory string, userInputFile string, configFiles []string, configType string, noFSS bool, userCreds string)

func ServiceStopTest

func ServiceStopTest(homeDirectory string)

Services are stopped in the reverse order they were started, parents first and then leaf nodes last in order to minimize the possibility of a parent throwing an error during execution because a leaf node is gone.

func ServiceValidate

func ServiceValidate(homeDirectory string, userInputFile string, configFiles []string, configType string, userCreds string) []string

func SetUserInputsVariableConfiguration

func SetUserInputsVariableConfiguration(homeDirectory string, sDef cliexchange.AbstractServiceFile, configuredVars []register.MicroWork) error

func StartContainers

func StartContainers(deployment *containermessage.DeploymentDescription,
	specRef string,
	version string,
	globals []register.GlobalSet,
	defUserInputs []exchange.UserInput,
	configUserInputs []register.MicroWork,
	org string,
	dc *cliexchange.DeploymentConfig,
	cw *container.ContainerWorker,
	msNetworks map[string]docker.ContainerNetwork,
	service bool,
	agreementBased bool,
	id string) (map[string]docker.ContainerNetwork, error)

func UpdateDependencyFile

func UpdateDependencyFile(homeDirectory string, sDef cliexchange.AbstractServiceFile) error

func UpdateDependentDependencies

func UpdateDependentDependencies(homeDirectory string, depProject string) error

Copy the dependency files out, validate them and write them back.

func UpdateServiceDefandUserInputFile

func UpdateServiceDefandUserInputFile(homeDirectory string, sDef cliexchange.AbstractServiceFile, skipServcieDef bool) error

update the service definition file and userinput file with this dependent service

func UpdateVariableConfiguration

func UpdateVariableConfiguration(homeDirectory string, sDef cliexchange.AbstractServiceFile, configuredVars []register.MicroWork) (*register.InputFile, error)

Given a userinput file, a dependency definition and a set of configured user input variables, copy the configured variables into the userinput file.

func UserInputExists

func UserInputExists(directory string) (bool, error)

Check for the existence of the user input config file in the project.

func ValidateDependencies

func ValidateDependencies(directory string, userInputs *register.InputFile, userInputsFilePath string, projectType string, userCreds string, autoAddDep bool) error

Validate that the dependencies are complete and coherent with the rest of the definitions in the project. Any errors will be returned to the caller.

func ValidateService

func ValidateService(directory string, fInfo os.FileInfo, userInputs *register.InputFile, userInputsFilePath string) error

func ValidateServiceDefinition

func ValidateServiceDefinition(directory string, fileName string) error

Validate that the service definition file is complete and coherent with the rest of the definitions in the project. If the file is not valid the reason will be returned in the error.

func ValidateUserInput

func ValidateUserInput(i *register.InputFile, directory string, originalUserInputFilePath string, projectType string) error

Validate that the userinputs file is complete and coherent with the rest of the definitions in the project. If the file is not valid the reason will be returned in the error.

func VerifyEnvironment

func VerifyEnvironment(homeDirectory string, mustExist bool, needExchange bool, userCreds string) (string, error)

Common verification before executing a sub command.

Types

type ServiceDependency

type ServiceDependency struct {
	Service    ServiceSpec
	TopSvcRefs []*ServiceSpec // the top services that eventually reference this service
	FileInfo   os.FileInfo
}

func NewServiceDependency

func NewServiceDependency(service *ServiceSpec, topService *ServiceSpec, fileInfo os.FileInfo) *ServiceDependency

func (*ServiceDependency) AddTopRef

func (sd *ServiceDependency) AddTopRef(topService *ServiceSpec)

Add a top service reference to this dependency

func (ServiceDependency) String

func (sd ServiceDependency) String() string

type ServiceSpec

type ServiceSpec struct {
	SpecRef string
	Org     string
	Version string
	Arch    string
}

func NewServiceSpec

func NewServiceSpec(specref, org, version, arch string) *ServiceSpec

func (ServiceSpec) Matches

func (sp ServiceSpec) Matches(sp2 ServiceSpec) bool

func (ServiceSpec) String

func (sp ServiceSpec) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL