Unverified Commit 10eb448d authored by Kevin Di Lallo's avatar Kevin Di Lallo Committed by GitHub
Browse files

Merge pull request #241 from dilallkx/kd_sp17_fix_model

Meep-model package improvements for getting active scenario nodes
parents c760a1bb f288c156
Loading
Loading
Loading
Loading
+78 −90
Original line number Diff line number Diff line
@@ -417,10 +417,10 @@ func ceGetActiveScenario(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(scenario))
}

func getNodeFilterFromQueryParams(query url.Values) mod.NodeFindFilter {
func getNodeFilterFromQueryParams(query url.Values) mod.NodeFilter {

	//Retrieve query parameters and populate filter
	var filter mod.NodeFindFilter
	var filter mod.NodeFilter
	minimizeStr := query.Get("minimize")
	if minimizeStr == "true" {
		filter.Minimize = true
@@ -450,26 +450,21 @@ func getNodeFilterFromQueryParams(query url.Values) mod.NodeFindFilter {
// Retrieves the active scenario domains
// GET /active/domains
func ceGetActiveScenarioDomain(w http.ResponseWriter, r *http.Request) {
	log.Debug("CEGetActiveScenarioDomain")
	log.Debug("ceGetActiveScenarioDomain")

	// Make sure scenario is active
	if sbxCtrl.activeModel == nil || !sbxCtrl.activeModel.Active {
		http.Error(w, "No scenario is active", http.StatusNotFound)
		return
	}

	//Retrieve query parameters and populate filter
	// Get filters from query params
	filter := getNodeFilterFromQueryParams(r.URL.Query())

	domains := sbxCtrl.activeModel.GetDomainNodesByFilter(&filter)
	// Get domains
	domains := sbxCtrl.activeModel.GetDomains(&filter)

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	if len(domains.Domains) == 0 {
		w.WriteHeader(http.StatusNotFound)
	} else {

		//var domains dataModel.Domains
		//domains.Domains = nodeListDomains
	// Format response
	jsonResponse, err := json.Marshal(domains)
	if err != nil {
		log.Error(err.Error())
@@ -477,32 +472,30 @@ func ceGetActiveScenarioDomain(w http.ResponseWriter, r *http.Request) {
		return
	}

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, string(jsonResponse))
}
}

// Retrieves the active scenario domains
// GET /active/zones
func ceGetActiveScenarioZone(w http.ResponseWriter, r *http.Request) {
	log.Debug("CEGetActiveScenarioZone")
	log.Debug("ceGetActiveScenarioZone")

	// Make sure scenario is active
	if sbxCtrl.activeModel == nil || !sbxCtrl.activeModel.Active {
		http.Error(w, "No scenario is active", http.StatusNotFound)
		return
	}

	//Retrieve query parameters and populate filter
	// Get filters from query params
	filter := getNodeFilterFromQueryParams(r.URL.Query())

	zones := sbxCtrl.activeModel.GetZoneNodesByFilter(&filter)

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	if len(zones.Zones) == 0 {
		w.WriteHeader(http.StatusNotFound)
	} else {
	// Get zones
	zones := sbxCtrl.activeModel.GetZones(&filter)

	// Format response
	jsonResponse, err := json.Marshal(zones)
	if err != nil {
		log.Error(err.Error())
@@ -510,32 +503,30 @@ func ceGetActiveScenarioZone(w http.ResponseWriter, r *http.Request) {
		return
	}

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, string(jsonResponse))
}
}

// Retrieves the active scenario domains
// GET /active/zones
// GET /active/networkLocations
func ceGetActiveScenarioNetworkLocation(w http.ResponseWriter, r *http.Request) {
	log.Debug("CEGetActiveScenarioNetworkLocation")
	log.Debug("ceGetActiveScenarioNetworkLocation")

	// Make sure scenario is active
	if sbxCtrl.activeModel == nil || !sbxCtrl.activeModel.Active {
		http.Error(w, "No scenario is active", http.StatusNotFound)
		return
	}

	//Retrieve query parameters and populate filter
	// Get filters from query params
	filter := getNodeFilterFromQueryParams(r.URL.Query())

	networkLocations := sbxCtrl.activeModel.GetNetworkLocationNodesByFilter(&filter)

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	if len(networkLocations.NetworkLocations) == 0 {
		w.WriteHeader(http.StatusNotFound)
	} else {
	// Get network locations
	networkLocations := sbxCtrl.activeModel.GetNetworkLocations(&filter)

	// Format response
	jsonResponse, err := json.Marshal(networkLocations)
	if err != nil {
		log.Error(err.Error())
@@ -543,32 +534,30 @@ func ceGetActiveScenarioNetworkLocation(w http.ResponseWriter, r *http.Request)
		return
	}

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, string(jsonResponse))
}
}

// Retrieves the active scenario domains
// GET /active/physicalLocations
func ceGetActiveScenarioPhysicalLocation(w http.ResponseWriter, r *http.Request) {
	log.Debug("CEGetActiveScenarioPhysicalLocation")
	log.Debug("ceGetActiveScenarioPhysicalLocation")

	// Make sure scenario is active
	if sbxCtrl.activeModel == nil || !sbxCtrl.activeModel.Active {
		http.Error(w, "No scenario is active", http.StatusNotFound)
		return
	}

	//Retrieve query parameters and populate filter
	// Get filters from query params
	filter := getNodeFilterFromQueryParams(r.URL.Query())

	physicalLocations := sbxCtrl.activeModel.GetPhysicalLocationNodesByFilter(&filter)

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	if len(physicalLocations.PhysicalLocations) == 0 {
		w.WriteHeader(http.StatusNotFound)
	} else {
	// Get physical locations
	physicalLocations := sbxCtrl.activeModel.GetPhysicalLocations(&filter)

	// Format response
	jsonResponse, err := json.Marshal(physicalLocations)
	if err != nil {
		log.Error(err.Error())
@@ -576,32 +565,30 @@ func ceGetActiveScenarioPhysicalLocation(w http.ResponseWriter, r *http.Request)
		return
	}

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, string(jsonResponse))
}
}

// Retrieves the active scenario domains
// GET /active/processes
func ceGetActiveScenarioProcess(w http.ResponseWriter, r *http.Request) {
	log.Debug("CEGetActiveScenarioProcess")
	log.Debug("ceGetActiveScenarioProcess")

	// Make sure scenario is active
	if sbxCtrl.activeModel == nil || !sbxCtrl.activeModel.Active {
		http.Error(w, "No scenario is active", http.StatusNotFound)
		return
	}

	//Retrieve query parameters and populate filter
	// Get filters from query params
	filter := getNodeFilterFromQueryParams(r.URL.Query())

	processes := sbxCtrl.activeModel.GetProcessNodesByFilter(&filter)

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	if len(processes.Processes) == 0 {
		w.WriteHeader(http.StatusNotFound)
	} else {
	// Get processes
	processes := sbxCtrl.activeModel.GetProcesses(&filter)

	// Format response
	jsonResponse, err := json.Marshal(processes)
	if err != nil {
		log.Error(err.Error())
@@ -609,10 +596,11 @@ func ceGetActiveScenarioProcess(w http.ResponseWriter, r *http.Request) {
		return
	}

	// Send response
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, string(jsonResponse))
}
}

// Retrieves service maps of the active scenario
// GET /active/serviceMaps
+26 −111
Original line number Diff line number Diff line
@@ -21,130 +21,45 @@ import (
)

// minimizeScenario - Minimizes scenario
func minimizeScenario(scenario *dataModel.Scenario) error {
	if scenario != nil {
		if scenario.Deployment != nil {
func minimizeScenario(scenario *dataModel.Scenario) {
	if scenario != nil && scenario.Deployment != nil {
		deployment := scenario.Deployment

			// Domains
			for iDomain := range deployment.Domains {
				domain := &deployment.Domains[iDomain]

				// Zones
				for iZone := range domain.Zones {
					zone := &domain.Zones[iZone]

					// Network Locations
					for iNL := range zone.NetworkLocations {
						nl := &zone.NetworkLocations[iNL]

						// Remove geodata
						nl.GeoData = nil

						// Physical Locations
						for iPL := range nl.PhysicalLocations {
							pl := &nl.PhysicalLocations[iPL]

							// Remove geodata
							pl.GeoData = nil

							// // Processes
							// for iProc := range pl.Processes {
							// 	proc := &pl.Processes[iProc]
							// }
		for i := range deployment.Domains {
			domain := &deployment.Domains[i]
			minimizeDomain(domain)
		}
	}
}
			}
		}
	}
	return nil
}

// minimizeDomain - Minimizes domain
func minimizeDomain(domain *dataModel.Domain) error {
                                // Zones
                                for iZone := range domain.Zones {
                                        zone := &domain.Zones[iZone]

                                        // Network Locations
                                        for iNL := range zone.NetworkLocations {
                                                nl := &zone.NetworkLocations[iNL]

                                                // Remove geodata
                                                nl.GeoData = nil

                                                // Physical Locations
                                                for iPL := range nl.PhysicalLocations {
                                                        pl := &nl.PhysicalLocations[iPL]

                                                        // Remove geodata
                                                        pl.GeoData = nil

                                                        // // Processes
                                                        // for iProc := range pl.Processes {
                                                        //      proc := &pl.Processes[iProc]
                                                        // }
                                                }
                                        }
func minimizeDomain(domain *dataModel.Domain) {
	for i := range domain.Zones {
		zone := &domain.Zones[i]
		minimizeZone(zone)
	}
        return nil
}

// minimizeZone - Minimizes zone
func minimizeZone(zone *dataModel.Zone) error {
                                        // Network Locations
                                        for iNL := range zone.NetworkLocations {
                                                nl := &zone.NetworkLocations[iNL]

                                                // Remove geodata
                                                nl.GeoData = nil

                                                // Physical Locations
                                                for iPL := range nl.PhysicalLocations {
                                                        pl := &nl.PhysicalLocations[iPL]

                                                        // Remove geodata
                                                        pl.GeoData = nil

                                                        // // Processes
                                                        // for iProc := range pl.Processes {
                                                        //      proc := &pl.Processes[iProc]
                                                        // }
func minimizeZone(zone *dataModel.Zone) {
	for i := range zone.NetworkLocations {
		nl := &zone.NetworkLocations[i]
		minimizeNetLoc(nl)
	}
}
        return nil
}

// minimizeNetLoc - Minimizes network location
func minimizeNetLoc(nl *dataModel.NetworkLocation) error {
func minimizeNetLoc(nl *dataModel.NetworkLocation) {
	// Remove geodata
	nl.GeoData = nil

                                                // Physical Locations
                                                for iPL := range nl.PhysicalLocations {
                                                        pl := &nl.PhysicalLocations[iPL]

                                                        // Remove geodata
                                                        pl.GeoData = nil

                                                        // // Processes
                                                        // for iProc := range pl.Processes {
                                                        //      proc := &pl.Processes[iProc]
                                                        // }
	for i := range nl.PhysicalLocations {
		pl := &nl.PhysicalLocations[i]
		minimizePhyLoc(pl)
	}
        return nil
}

// minimizePlyLoc - Minimizes physical location
func minimizePhyLoc(pl *dataModel.PhysicalLocation) error {
func minimizePhyLoc(pl *dataModel.PhysicalLocation) {
	// Remove geodata
	pl.GeoData = nil

                                                        // // Processes
                                                        // for iProc := range pl.Processes {
                                                        //      proc := &pl.Processes[iProc]
                                                        // }
        return nil
}
Loading