Пример #1
0
// @Title delete
// @Description delete the cluster application deployment
// @Param clusterApplicationName path string true "The name of cluster application deployment"
// @Success 200 {string} {}
// @Failure 404 error reason
// @router /:clusterApplicationName [delete]
func (c *DeleteController) Delete() {
	clusterApplicationName := c.GetString(":clusterApplicationName")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	namespace := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deployclusterapplications/" + namespace + "/" + clusterApplicationName

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = make(map[string]interface{})
		c.ServeJSON()
	}
}
Пример #2
0
func (c *PodDeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	namespace := c.GetString("namespace")
	pod := c.GetString("pod")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/pods/" + namespace + "/" + pod

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Pod " + pod + " is deleted")
	}

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/inventory/replicationcontroller/list")

	guimessage.RedirectMessage(c)
}
Пример #3
0
func (c *DeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	imageInformation := c.GetString("imageInformation")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploybluegreens/" + imageInformation

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Deploy blue green deployment " + imageInformation + " is deleted")
	}

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/deploy/deploybluegreen/list")

	guimessage.RedirectMessage(c)
}
Пример #4
0
func (c *DeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	serverName := c.GetString("serverName")
	repositoryName := c.GetString("repositoryName")
	tag := c.GetString("tag")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/privateregistries/servers/" + serverName + "/repositories/" + repositoryName + "/tags/" + tag

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Image labeled with the tag " + tag + " is deleted")
	}

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/system/privateregistry/image/list?serverName="+serverName+"&repositoryName="+repositoryName)

	guimessage.RedirectMessage(c)
}
Пример #5
0
func (c *DeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	name := c.GetString("name")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/notifiers/emailserversmtp/" + name

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Email server configuration " + name + " is deleted")
	}

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/system/notification/emailserver/list")

	guimessage.RedirectMessage(c)
}
Пример #6
0
func (c *DeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	imageInformationName := c.GetString("name")
	imageRecordVersion := c.GetString("version")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/imagerecords/" + imageInformationName + "/" + imageRecordVersion

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Image record " + imageRecordVersion + " belonging to " + imageInformationName + " is deleted")
	}

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/repository/imagerecord/list?name="+imageInformationName)

	guimessage.RedirectMessage(c)
}
Пример #7
0
func (c *DeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	clusterName := c.GetString("clusterName")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	glusterfsVolume := c.GetString("glusterfsVolume")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/glusterfs/clusters/" + clusterName + "/volumes/" + glusterfsVolume

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Glusterfs volume " + glusterfsVolume + " is deleted")
	}

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/filesystem/glusterfs/volume/list?clusterName="+clusterName)

	guimessage.RedirectMessage(c)
}
Пример #8
0
func (privateRegistry *PrivateRegistry) DeleteImageInRepository(repositoryName string, tag string) error {
	request, err := http.NewRequest("GET", privateRegistry.getPrivateRegistryEndpoint()+"/v2/"+repositoryName+"/manifests/"+tag, nil)
	if err != nil {
		log.Error(err)
		return err
	}

	// For registry version 2.3 and later
	request.Header.Add("Accept", "application/vnd.docker.distribution.manifest.v2+json")
	response, err := restclient.GetInsecureHTTPSClient().Do(request)
	if err != nil {
		log.Error(err)
		return err
	}
	digest := response.Header.Get("Docker-Content-Digest")

	if len(digest) == 0 {
		// The tag has no image
		return nil
	}

	_, err = restclient.RequestDelete(privateRegistry.getPrivateRegistryEndpoint()+"/v2/"+repositoryName+"/manifests/"+digest, nil, nil, false)
	requestError, _ := err.(restclient.RequestError)
	if requestError.StatusCode == 404 {
		// Not found so the target doesn't exist
		return nil
	}
	if err != nil {
		log.Error(err)
		return err
	}

	return nil
}
Пример #9
0
func (c *DeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	ip := c.GetString("ip")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/hosts/credentials/" + ip

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Credential " + ip + " is deleted")
	}

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/system/host/credential/list")

	guimessage.RedirectMessage(c)
}
Пример #10
0
func DeleteReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("DeleteReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName
	_, err := restclient.RequestDelete(url, nil, headerMap, true)
	return err
}
Пример #11
0
func DeleteNamespace(kubeApiServerEndPoint string, kubeApiServerToken string, name string) (returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("DeleteNamespace Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	_, err := restclient.RequestDelete(kubeApiServerEndPoint+"/api/v1/namespaces/"+name, nil, headerMap, true)
	if err != nil {
		log.Error("Fail to delete namespace with endpoint: %s, token: %s, name: %s, error: %s", kubeApiServerEndPoint, kubeApiServerToken, name, err.Error())
		return err
	}

	return nil
}
Пример #12
0
func DeleteEvent(kubeApiServerEndPoint string, kubeApiServerToken string, selfLink string) (returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("DeleteEvent Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	_, err := restclient.RequestDelete(kubeApiServerEndPoint+selfLink, nil, headerMap, true)
	if err != nil {
		log.Error("Fail to delete event selfLink %s with endpoint: %s, token: %s, error: %s", selfLink, kubeApiServerEndPoint, kubeApiServerToken, err.Error())
		return err
	}

	return nil
}
Пример #13
0
// @Title delete
// @Description delete the namespace
// @Param name path string true "The name of namespace"
// @Success 200 {string} {}
// @Failure 404 error reason
// @router /:name [delete]
func (c *DeleteController) Delete() {
	name := c.GetString(":name")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/namespaces/" + name

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		selectedNamespace := c.GetSession("namespace")
		if selectedNamespace.(string) == name {
			c.SetSession("namespace", "default")
		}

		time.Sleep(1000 * time.Millisecond)

		c.Data["json"] = make(map[string]interface{})
		c.ServeJSON()
	}
}
Пример #14
0
func RequestDeleteBuildLog(imageInformationName string, imageRecordVersion string) error {
	cloudoneAnalysisHost, ok := configuration.LocalConfiguration.GetString("cloudoneAnalysisHost")
	if ok == false {
		log.Error("Fail to get configuration cloudoneAnalysisHost")
		return errors.New("Fail to get configuration cloudoneAnalysisHost")
	}
	cloudoneAnalysisPort, ok := configuration.LocalConfiguration.GetInt("cloudoneAnalysisPort")
	if ok == false {
		log.Error("Fail to get configuration cloudoneAnalysisPort")
		return errors.New("Fail to get configuration cloudoneAnalysisPort")
	}

	url := "https://" + cloudoneAnalysisHost + ":" + strconv.Itoa(cloudoneAnalysisPort) + "/api/v1/buildlogs/" + imageInformationName + "/" + imageRecordVersion

	headerMap := make(map[string]string)
	headerMap["token"] = authorization.SystemAdminToken

	_, err := restclient.RequestDelete(url, nil, headerMap, false)
	if err != nil {
		log.Error("Fail to request delete build image information %s version %s log with error %s", imageInformationName, imageRecordVersion, err)
	}

	return err
}
Пример #15
0
func (c *DeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	name := c.GetString("name")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	// Delete deploy
	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploys/" + name

	deployInformationSlice := make([]deploy.DeployInformation, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &deployInformationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for _, deployInformation := range deployInformationSlice {
			url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
				"/api/v1/deploys/" + name + "/" + deployInformation.ImageInformationName

			_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

			if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
				return
			}

			if err != nil {
				guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
			}
		}
	}

	// Delete third party service
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deployclusterapplications/" + name

	deployClusterApplicationSlice := make([]deployclusterapplication.DeployClusterApplication, 0)
	_, err = restclient.RequestGetWithStructure(url, &deployClusterApplicationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for _, deployClusterApplication := range deployClusterApplicationSlice {
			url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
				"/api/v1/deployclusterapplications/" + name + "/" + deployClusterApplication.Name

			_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

			if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
				return
			}

			if err != nil {
				guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
			}
		}
	}

	// Delete namespace
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/namespaces/" + name

	_, err = restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Namespace " + name + " is deleted")

		selectedNamespace := c.GetSession("namespace")
		if selectedNamespace.(string) == name {
			c.SetSession("namespace", "default")
		}
	}

	// Delete autoscaler
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/autoscalers/"

	replicationControllerAutoScalerSlice := make([]autoscaler.ReplicationControllerAutoScaler, 0)
	_, err = restclient.RequestGetWithStructure(url, &replicationControllerAutoScalerSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for _, replicationControllerAutoScaler := range replicationControllerAutoScalerSlice {
			if replicationControllerAutoScaler.Namespace == name {
				url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
					"/api/v1/autoscalers/" + name + "/" + replicationControllerAutoScaler.Kind + "/" + replicationControllerAutoScaler.Name

				_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

				if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
					return
				}

				if err != nil {
					guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
				}
			}
		}
	}

	// Delete notifier
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/notifiers/"

	replicationControllerNotifierSlice := make([]notifier.ReplicationControllerNotifier, 0)
	_, err = restclient.RequestGetWithStructure(url, &replicationControllerNotifierSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for _, replicationControllerNotifier := range replicationControllerNotifierSlice {
			if replicationControllerNotifier.Namespace == name {
				url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
					"/api/v1/notifiers/" + name + "/" + replicationControllerNotifier.Kind + "/" + replicationControllerNotifier.Name

				_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

				if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
					return
				}

				if err != nil {
					guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
				}
			}
		}
	}

	// Since the name deletion is asynchronized, wait for some time
	time.Sleep(time.Millisecond * 500)

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/system/namespace/list")

	guimessage.RedirectMessage(c)
}