當前位置: 首頁>>代碼示例>>Golang>>正文


Golang errors.NewError函數代碼示例

本文整理匯總了Golang中github.com/openshift/origin/pkg/bootstrap/docker/errors.NewError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewError函數的具體用法?Golang NewError怎麽用?Golang NewError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CheckAvailablePorts

// CheckAvailablePorts ensures that ports used by OpenShift are available on the Docker host
func (c *ClientStartConfig) CheckAvailablePorts(out io.Writer) error {
	c.DNSPort = openshift.DefaultDNSPort
	err := c.OpenShiftHelper().TestPorts(openshift.AllPorts)
	if err == nil {
		return nil
	}
	if !openshift.IsPortsNotAvailableErr(err) {
		return err
	}
	unavailable := sets.NewInt(openshift.UnavailablePorts(err)...)
	if unavailable.HasAny(openshift.BasePorts...) {
		return errors.NewError("a port needed by OpenShift is not available").WithCause(err)
	}
	if unavailable.Has(openshift.DefaultDNSPort) {
		if unavailable.Has(openshift.AlternateDNSPort) {
			return errors.NewError("a port needed by OpenShift is not available").WithCause(err)
		}
		c.DNSPort = openshift.AlternateDNSPort
		fmt.Fprintf(out, "WARNING: Binding DNS on port %d instead of 53, which may not be resolvable from all clients.\n", openshift.AlternateDNSPort)
	}

	for _, port := range openshift.RouterPorts {
		if unavailable.Has(port) {
			fmt.Fprintf(out, "WARNING: Port %d is already in use and may cause routing issues for applications.\n", port)
		}
	}
	return nil
}
開發者ID:php-coder,項目名稱:origin,代碼行數:29,代碼來源:up.go

示例2: CheckAndPull

// CheckAndPull checks whether a Docker image exists. If not, it pulls it.
func (h *Helper) CheckAndPull(image string, out io.Writer) error {
	glog.V(5).Infof("Inspecting Docker image %q", image)
	imageMeta, err := h.client.InspectImage(image)
	if err == nil {
		glog.V(5).Infof("Image %q found: %#v", image, imageMeta)
		return nil
	}
	if err != docker.ErrNoSuchImage {
		return starterrors.NewError("unexpected error inspecting image %s", image).WithCause(err)
	}
	glog.V(5).Infof("Image %q not found. Pulling", image)
	fmt.Fprintf(out, "Pulling image %s\n", image)
	logProgress := func(s string) {
		fmt.Fprintf(out, "%s\n", s)
	}
	outputStream := imageprogress.NewPullWriter(logProgress)
	if glog.V(5) {
		outputStream = out
	}
	err = h.client.PullImage(docker.PullImageOptions{
		Repository:    image,
		RawJSONStream: bool(!glog.V(5)),
		OutputStream:  outputStream,
	}, docker.AuthConfiguration{})
	if err != nil {
		return starterrors.NewError("error pulling Docker image %s", image).WithCause(err)
	}
	fmt.Fprintf(out, "Image pull complete\n")
	return nil
}
開發者ID:juanluisvaladas,項目名稱:origin,代碼行數:31,代碼來源:helper.go

示例3: Status

// Status prints the OpenShift cluster status
func (c *ClientStatusConfig) Status(f *clientcmd.Factory, out io.Writer) error {
	dockerClient, _, err := getDockerClient(out, c.DockerMachine, false)
	if err != nil {
		return errors.ErrNoDockerClient(err)
	}
	helper := dockerhelper.NewHelper(dockerClient, nil)

	container, running, err := helper.GetContainerState(openshift.OpenShiftContainer)
	if err != nil {
		return errors.NewError("cannot get state of OpenShift container %s", openshift.OpenShiftContainer).WithCause(err)
	}

	if !running {
		return errors.NewError("OpenShift cluster is not running")
	}

	healthy, err := isHealthy(f)
	if err != nil {
		return err
	}
	if !healthy {
		return errors.NewError("OpenShift cluster health check failed")
	}

	config, err := openshift.GetConfigFromContainer(dockerClient)
	if err != nil {
		return err
	}

	fmt.Print(status(container, config))

	return nil
}
開發者ID:juanluisvaladas,項目名稱:origin,代碼行數:34,代碼來源:status.go

示例4: instantiateTemplate

func instantiateTemplate(client client.Interface, mapper configcmd.Mapper, templateNamespace, templateName, targetNamespace string, params map[string]string) error {
	template, err := client.Templates(templateNamespace).Get(templateName)
	if err != nil {
		return errors.NewError("cannot retrieve template %q from namespace %q", templateName, templateNamespace).WithCause(err)
	}

	// process the template
	result, err := genappcmd.TransformTemplate(template, client, targetNamespace, params)
	if err != nil {
		return errors.NewError("cannot process template %s/%s", templateNamespace, templateName).WithCause(err)
	}

	// Create objects
	bulk := &configcmd.Bulk{
		Mapper: mapper,
		Op:     configcmd.Create,
	}
	itemsToCreate := &kapi.List{
		Items: result.Objects,
	}
	if errs := bulk.Run(itemsToCreate, targetNamespace); len(errs) > 0 {
		err = kerrors.NewAggregate(errs)
		return errors.NewError("cannot create objects from template %s/%s", templateNamespace, templateName).WithCause(err)
	}

	return nil
}
開發者ID:LalatenduMohanty,項目名稱:origin,代碼行數:27,代碼來源:logging.go

示例5: CheckAndPull

// CheckAndPull checks whether a Docker image exists. If not, it pulls it.
func (h *Helper) CheckAndPull(image string, out io.Writer) error {
	glog.V(5).Infof("Inspecting Docker image %q", image)
	imageMeta, err := h.client.InspectImage(image)
	if err == nil {
		glog.V(5).Infof("Image %q found: %#v", image, imageMeta)
		return nil
	}
	if err != docker.ErrNoSuchImage {
		return starterrors.NewError("unexpected error inspecting image %s", image).WithCause(err)
	}
	glog.V(5).Infof("Image %q not found. Pulling", image)
	fmt.Fprintf(out, "Pulling image %s\n", image)
	extracting := false
	var outputStream io.Writer
	writeProgress := func(r *pullprogress.ProgressReport) {
		if extracting {
			return
		}
		if r.Downloading == 0 && r.Waiting == 0 && r.Extracting > 0 {
			fmt.Fprintf(out, "Extracting\n")
			extracting = true
			return
		}
		plural := "s"
		if r.Downloading == 1 {
			plural = " "
		}
		fmt.Fprintf(out, "Downloading %d layer%s (%3.0f%%)", r.Downloading, plural, r.DownloadPct)
		if r.Waiting > 0 {
			fmt.Fprintf(out, ", %d waiting\n", r.Waiting)
		} else {
			fmt.Fprintf(out, "\n")
		}
	}
	if !glog.V(5) {
		outputStream = pullprogress.NewPullProgressWriter(writeProgress)
	} else {
		outputStream = out
	}
	err = h.client.PullImage(docker.PullImageOptions{
		Repository:    image,
		RawJSONStream: bool(!glog.V(5)),
		OutputStream:  outputStream,
	}, docker.AuthConfiguration{})
	if err != nil {
		return starterrors.NewError("error pulling Docker image %s", image).WithCause(err)
	}
	fmt.Fprintf(out, "Image pull comlete\n")
	return nil
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:51,代碼來源:helper.go

示例6: TestIP

func (h *Helper) TestIP(ip string) error {

	// Start test server on host
	id, err := h.runHelper.New().Image(h.image).
		Privileged().
		HostNetwork().
		Entrypoint("socat").
		Command("TCP-LISTEN:8443,crlf,reuseaddr,fork", "SYSTEM:\"echo 'hello world'\"").Start()
	if err != nil {
		return errors.NewError("cannnot start simple server on Docker host").WithCause(err)
	}
	defer func() {
		errors.LogError(h.dockerHelper.StopAndRemoveContainer(id))
	}()

	// Attempt to connect to test container
	testHost := fmt.Sprintf("%s:8443", ip)
	glog.V(4).Infof("Attempting to dial %s", testHost)
	if err = cmdutil.WaitForSuccessfulDial(false, "tcp", testHost, 200*time.Millisecond, 1*time.Second, 10); err != nil {
		glog.V(2).Infof("Dial error: %v", err)
		return err
	}
	glog.V(4).Infof("Successfully dialed %s", testHost)
	return nil
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:25,代碼來源:helper.go

示例7: EnsureHostDirectories

func (h *HostHelper) EnsureHostDirectories() error {
	// Attempt to create host directories only if they are
	// the default directories. If the user specifies them, then the
	// user is responsible for ensuring they exist, are mountable, etc.
	dirs := []string{}
	if h.configDir == DefaultConfigDir {
		dirs = append(dirs, path.Join("/rootfs", h.configDir))
	}
	if h.volumesDir == DefaultVolumesDir {
		dirs = append(dirs, path.Join("/rootfs", h.volumesDir))
	}
	if len(dirs) > 0 {
		cmd := fmt.Sprintf(cmdEnsureHostDirs, strings.Join(dirs, " "))
		rc, err := h.runner().
			Image(h.image).
			DiscardContainer().
			Privileged().
			Bind("/var:/rootfs/var").
			Entrypoint("/bin/bash").
			Command("-c", cmd).Run()
		if err != nil || rc != 0 {
			return errors.NewError("cannot create host volumes directory").WithCause(err)
		}
	}
	return nil
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:26,代碼來源:host.go

示例8: InstallRegistry

// InstallRegistry checks whether a registry is installed and installs one if not already installed
func (h *Helper) InstallRegistry(kubeClient kclient.Interface, f *clientcmd.Factory, configDir, images string, out io.Writer) error {
	_, err := kubeClient.Services("default").Get(svcDockerRegistry)
	if err == nil {
		// If there's no error, the registry already exists
		return nil
	}
	if !apierrors.IsNotFound(err) {
		return errors.NewError("error retrieving docker registry service").WithCause(err)
	}
	imageTemplate := variable.NewDefaultImageTemplate()
	imageTemplate.Format = images
	cfg := &registry.RegistryConfig{
		Name:           "registry",
		Type:           "docker-registry",
		ImageTemplate:  imageTemplate,
		Ports:          "5000",
		Replicas:       1,
		Labels:         "docker-registry=default",
		Volume:         "/registry",
		ServiceAccount: "registry",
	}
	cmd := registry.NewCmdRegistry(f, "", "registry", out)
	output := &bytes.Buffer{}
	err = registry.RunCmdRegistry(f, cmd, output, cfg, []string{})
	glog.V(4).Infof("Registry command output:\n%s", output.String())
	return err
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:28,代碼來源:admin.go

示例9: startContainer

func (h *Runner) startContainer(id string) error {
	err := h.client.StartContainer(id, nil)
	if err != nil {
		return errors.NewError("cannot start container %s", id).WithCause(err)
	}
	return nil
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:7,代碼來源:run.go

示例10: ensureVolumesDirShare

func (h *HostHelper) ensureVolumesDirShare() error {
	cmd := fmt.Sprintf(cmdCreateVolumesDirShare, h.volumesDir)
	rc, err := h.hostPidCmd(cmd)
	if err != nil || rc != 0 {
		return errors.NewError("cannot create volumes dir share").WithCause(err)
	}
	return nil
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:8,代碼來源:host.go

示例11: CheckExistingOpenShiftContainer

// CheckExistingOpenShiftContainer checks the state of an OpenShift container. If one
// is already running, it throws an error. If one exists, it removes it so a new one
// can be created.
func (c *ClientStartConfig) CheckExistingOpenShiftContainer(out io.Writer) error {
	exists, running, err := c.DockerHelper().GetContainerState(openShiftContainer)
	if err != nil {
		return errors.NewError("unexpected error while checking OpenShift container state").WithCause(err)
	}
	if running {
		return errors.NewError("OpenShift is already running").WithSolution("To start OpenShift again, stop current %q container.", openShiftContainer)
	}
	if exists {
		err = c.DockerHelper().RemoveContainer(openShiftContainer)
		if err != nil {
			return errors.NewError("cannot delete existing OpenShift container").WithCause(err)
		}
		fmt.Fprintf(out, "Deleted existing OpenShift container\n")
	}
	return nil
}
開發者ID:bmeng,項目名稱:origin,代碼行數:20,代碼來源:up.go

示例12: newRunError

func newRunError(rc int, cause error, stdOut, errOut []byte, config *docker.Config) error {
	return &runError{
		error:  errors.NewError("Docker run error rc=%d", rc).WithCause(cause),
		out:    stdOut,
		err:    errOut,
		config: config,
	}
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:8,代碼來源:errors.go

示例13: exec

func exec(h *ExecHelper, cmd []string, stdIn io.Reader, stdOut, errOut io.Writer) error {
	glog.V(4).Infof("Remote exec on container: %s\nCommand: %v", h.container, cmd)
	exec, err := h.client.CreateExec(docker.CreateExecOptions{
		AttachStdin:  stdIn != nil,
		AttachStdout: true,
		AttachStderr: true,
		Cmd:          cmd,
		Container:    h.container,
	})
	if err != nil {
		return errors.NewError("Cannot create exec for command %v on container %s", cmd, h.container).WithCause(err)
	}
	glog.V(5).Infof("Created exec %q", exec.ID)
	logOut, logErr := &bytes.Buffer{}, &bytes.Buffer{}
	outStream := io.MultiWriter(stdOut, logOut)
	errStream := io.MultiWriter(errOut, logErr)
	glog.V(5).Infof("Starting exec %q and blocking", exec.ID)
	err = h.client.StartExec(exec.ID, docker.StartExecOptions{
		InputStream:  stdIn,
		OutputStream: outStream,
		ErrorStream:  errStream,
	})
	if err != nil {
		return errors.NewError("Cannot start exec for command %v on container %s", cmd, h.container).WithCause(err)
	}
	if glog.V(5) {
		glog.Infof("Exec %q completed", exec.ID)
		if logOut.Len() > 0 {
			glog.Infof("Stdout:\n%s", logOut.String())
		}
		if logErr.Len() > 0 {
			glog.Infof("Stderr:\n%s", logErr.String())
		}
	}
	glog.V(5).Infof("Inspecting exec %q", exec.ID)
	info, err := h.client.InspectExec(exec.ID)
	if err != nil {
		return errors.NewError("Cannot inspect result of exec for command %v on container %s", cmd, h.container).WithCause(err)
	}
	glog.V(5).Infof("Exec %q info: %#v", exec.ID, info)
	if info.ExitCode != 0 {
		return newExecError(err, info.ExitCode, logOut.Bytes(), logErr.Bytes(), h.container, cmd)
	}
	return nil
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:45,代碼來源:exec.go

示例14: DetermineServerIP

// DetermineServerIP gets an appropriate IP address to communicate with the OpenShift server
func (c *ClientStartConfig) DetermineServerIP(out io.Writer) error {
	ip, err := c.determineIP(out)
	if err != nil {
		return errors.NewError("cannot determine a server IP to use").WithCause(err)
	}
	c.ServerIP = ip
	fmt.Fprintf(out, "Using %s as the server IP\n", ip)
	return nil
}
開發者ID:bmeng,項目名稱:origin,代碼行數:10,代碼來源:up.go

示例15: InstallMetrics

// InstallMetrics checks whether metrics is installed and installs it if not already installed
func (h *Helper) InstallMetrics(f *clientcmd.Factory, hostName, imagePrefix, imageVersion string) error {
	osClient, kubeClient, err := f.Clients()
	if err != nil {
		return errors.NewError("cannot obtain API clients").WithCause(err).WithDetails(h.OriginLog())
	}

	_, err = kubeClient.Services(infraNamespace).Get(svcMetrics)
	if err == nil {
		// If there's no error, the metrics service already exists
		return nil
	}
	if !apierrors.IsNotFound(err) {
		return errors.NewError("error retrieving metrics service").WithCause(err).WithDetails(h.OriginLog())
	}

	// Create metrics deployer service account
	routerSA := &kapi.ServiceAccount{}
	routerSA.Name = metricsDeployerSA
	_, err = kubeClient.ServiceAccounts(infraNamespace).Create(routerSA)
	if err != nil {
		return errors.NewError("cannot create metrics deployer service account").WithCause(err).WithDetails(h.OriginLog())
	}

	// Add edit role to deployer service account
	if err = AddRoleToServiceAccount(osClient, "edit", metricsDeployerSA, infraNamespace); err != nil {
		return errors.NewError("cannot add edit role to metrics deployer service account").WithCause(err).WithDetails(h.OriginLog())
	}

	// Add view role to the hawkular service account
	if err = AddRoleToServiceAccount(osClient, "view", "hawkular", infraNamespace); err != nil {
		return errors.NewError("cannot add view role to the hawkular service account").WithCause(err).WithDetails(h.OriginLog())
	}

	// Add cluster reader role to heapster service account
	if err = AddClusterRole(osClient, "cluster-reader", "system:serviceaccount:openshift-infra:heapster"); err != nil {
		return errors.NewError("cannot add cluster reader role to heapster service account").WithCause(err).WithDetails(h.OriginLog())
	}

	// Create metrics deployer secret
	deployerSecret := &kapi.Secret{}
	deployerSecret.Name = metricsDeployerSecret
	deployerSecret.Data = map[string][]byte{"nothing": []byte("/dev/null")}
	if _, err = kubeClient.Secrets(infraNamespace).Create(deployerSecret); err != nil {
		return errors.NewError("cannot create metrics deployer secret").WithCause(err).WithDetails(h.OriginLog())
	}

	// Create deployer Pod
	deployerPod := metricsDeployerPod(hostName, imagePrefix, imageVersion)
	if _, err = kubeClient.Pods(infraNamespace).Create(deployerPod); err != nil {
		return errors.NewError("cannot create metrics deployer pod").WithCause(err).WithDetails(h.OriginLog())
	}
	return nil
}
開發者ID:juanluisvaladas,項目名稱:origin,代碼行數:54,代碼來源:metrics.go


注:本文中的github.com/openshift/origin/pkg/bootstrap/docker/errors.NewError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。