@@ -69,6 +69,10 @@ func (repman *ReplicationManager) apiAppProtectedHandler(router *mux.Router) {
6969 negroni .HandlerFunc (repman .validateTokenMiddleware ),
7070 negroni .Wrap (http .HandlerFunc (repman .handlerMuxAppProvision )),
7171 ))
72+ router .Handle ("/api/clusters/{clusterName}/apps/{appName}/actions/update-routes" , negroni .New (
73+ negroni .HandlerFunc (repman .validateTokenMiddleware ),
74+ negroni .Wrap (http .HandlerFunc (repman .handlerMuxAppUpdateRoutes )),
75+ )).Methods ("POST" )
7276 router .Handle ("/api/clusters/{clusterName}/apps/{appName}/actions/stop" , negroni .New (
7377 negroni .HandlerFunc (repman .validateTokenMiddleware ),
7478 negroni .Wrap (http .HandlerFunc (repman .handlerMuxAppStop )),
@@ -829,6 +833,51 @@ func (repman *ReplicationManager) handlerMuxAppProvision(w http.ResponseWriter,
829833 }
830834}
831835
836+ // @Summary Update App Routes
837+ // @Description Push route configuration to the OpenSVC gateway service for a given app
838+ // @Tags Apps
839+ // @Accept json
840+ // @Produce json
841+ // @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
842+ // @Param clusterName path string true "Cluster Name"
843+ // @Param appName path string true "App Name"
844+ // @Success 200 {string} string "App Routes Updated"
845+ // @Failure 403 {string} string "No valid ACL"
846+ // @Failure 404 {string} string "App Not Found"
847+ // @Failure 500 {string} string "Cluster Not Found"
848+ // @Router /api/clusters/{clusterName}/apps/{appName}/actions/update-routes [post]
849+ func (repman * ReplicationManager ) handlerMuxAppUpdateRoutes (w http.ResponseWriter , r * http.Request ) {
850+ w .Header ().Set ("Access-Control-Allow-Origin" , "*" )
851+ vars := mux .Vars (r )
852+ mycluster := repman .getClusterByName (vars ["clusterName" ])
853+ if mycluster != nil {
854+ if valid , _ := repman .IsValidClusterACL (r , mycluster ); ! valid {
855+ http .Error (w , "No valid ACL" , http .StatusForbidden )
856+ return
857+ }
858+
859+ if mycluster .GetOrchestrator () != "opensvc" {
860+ http .Error (w , "Orchestrator not supported" , http .StatusInternalServerError )
861+ return
862+ }
863+
864+ node := mycluster .GetAppFromName (vars ["appName" ])
865+ if node != nil {
866+ if err := mycluster .OpenSVCProvisionRoute (node ); err != nil {
867+ http .Error (w , "Failed to update app routes: " + err .Error (), http .StatusInternalServerError )
868+ return
869+ }
870+ fmt .Fprintf (w , "App Routes Updated" )
871+ } else {
872+ http .Error (w , "App Not Found" , http .StatusNotFound )
873+ return
874+ }
875+ } else {
876+ http .Error (w , "Cluster Not Found" , http .StatusInternalServerError )
877+ return
878+ }
879+ }
880+
832881// @Summary Unprovision App Service
833882// @Description Unprovision the app service for a given cluster and app
834883// @Tags Apps
0 commit comments