Esempio n. 1
0
// CheckAsyncDeploy checks the given AsyncProcessId on the given instance, and prints the result to console.
// This function returns the response.Result.Done value, which will be true once the job has completed.
func CheckAsyncDeploy(id metadata.ID, instance Instance) (done bool) {

	login := new(metadata.BasicAuth)
	login.SessionId = instance.UserInfo.SessionID

	port := metadata.NewMetadataPortType(instance.MetadataURL, true, login)

	status := new(metadata.CheckDeployStatus)
	status.IncludeDetails = true
	status.AsyncProcessId = &id
	response, err := port.CheckDeployStatus(status)

	if err != nil {
		fmt.Println("Check deploy failed! Error: " + err.Error())
		return true
	}

	result := *response.Result
	details := *result.Details
	resultStatus := *result.Status

	if result.ErrorStatusCode != nil {
		code := *result.ErrorStatusCode
		fmt.Println(code)
	}

	fmt.Println(resultStatus)
	fmt.Println()

	if len(details.ComponentFailures) > 0 {
		fmt.Println("Failures:")

		for _, v := range details.ComponentFailures {
			fmt.Println(v.FileName)
			fmt.Println(int(v.LineNumber), ":", "[", string(*v.ProblemType), "]", v.Problem)
		}

		fmt.Println()

		return true
	}

	return response.Result.Done
}
Esempio n. 2
0
func TryDeploy(contents []byte, url, sessionId string) (success bool, err error) {

	login := new(metadata.BasicAuth)
	login.SessionId = sessionId

	options := new(metadata.DeployOptions)
	options.SinglePackage = true

	deploy := new(metadata.Deploy)
	deploy.DeployOptions = options

	b64 := base64.StdEncoding.EncodeToString(contents)

	port := metadata.NewMetadataPortType(url, false, login)

	response, err := port.Deploy(deploy)

	if err != nil {
		return
	}

	for true {
		time.Sleep(20)

		status := new(metadata.CheckDeployStatus)
		status.IncludeDetails = true
		status.AsyncProcessId = response.Result.Id
		statusResponse, err := port.CheckDeployStatus(status)

		if err != nil {
			success = false
			return
		}

		if statusResponse.Result.Done {
			fmt.Println(statusResponse.Result.Status)
			fmt.Println(statusResponse.Result.Details)

			success = true
			return
		}
	}
}