Unverified Commit 5b287368 authored by Kevin Di Lallo's avatar Kevin Di Lallo Committed by GitHub
Browse files

Merge pull request #330 from dilallkx/kd_sp47_dev_appid

App Instance ID in Frontend
parents e37e3c2e 1557a5b4
Loading
Loading
Loading
Loading
+68 −17
Original line number Diff line number Diff line
@@ -242,29 +242,22 @@ func (gc *GarbageCollector) getSandboxFromKey(key string, userData interface{})
}

func (gc *GarbageCollector) gcInfluxData() {
	// Get list of influx database names
	dbNameMap := make(map[string]bool)
	q := influx.NewQuery("SHOW DATABASES", "", "")
	response, err := (*gc.influxClient).Query(q)
	// Get map of influx database names
	dbNameMap, err := gc.getInfluxDbNames()
	if err != nil {
		log.Error("Failed to retrieve influx databases with error: ", err.Error())
		return
	}
	values, err := getResponseValues(response)

	// Get map of previously deployed sandbox names
	prevSboxMap, err := gc.getInfluxSandboxNames()
	if err != nil {
		log.Error("Failed to process influx response with error: ", err.Error())
		log.Error("Failed to retrieve sandbox names with error: ", err.Error())
		return
	}
	for _, val := range values {
		if dbName, found := val["name"]; found {
			if dbNameStr, ok := dbName.(string); ok {
				dbNameMap[dbNameStr] = true
			}
		}
	}

	// Get map of active sandboxes
	activeSbxMap, err := gc.getActiveSandboxMap()
	activeSboxMap, err := gc.getActiveSandboxMap()
	if err != nil {
		return
	}
@@ -287,6 +280,7 @@ func (gc *GarbageCollector) gcInfluxData() {
		}

		// Ignore DB names from user-provided exception list
		match = false
		for _, exception := range gc.cfg.InfluxExceptions {
			if dbName == exception {
				match = true
@@ -298,7 +292,8 @@ func (gc *GarbageCollector) gcInfluxData() {
		}

		// Ignore DB names with active sandbox prefix match
		for sbxName := range activeSbxMap {
		match = false
		for sbxName := range activeSboxMap {
			if sbxName != "" && strings.HasPrefix(dbNameDashes, sbxName+"-") {
				match = true
				break
@@ -308,9 +303,21 @@ func (gc *GarbageCollector) gcInfluxData() {
			continue
		}

		// Make sure database is associated with a previous sandbox name
		match = false
		for sbxName := range prevSboxMap {
			if sbxName != "" && strings.HasPrefix(dbNameDashes, sbxName+"-") {
				match = true
				break
			}
		}
		if !match {
			continue
		}

		// Flush database if no match found
		log.Info("Clearing inactive Influx database: ", dbName)
		q = influx.NewQuery("DROP DATABASE "+dbName, "", "")
		q := influx.NewQuery("DROP DATABASE "+dbName, "", "")
		_, err := (*gc.influxClient).Query(q)
		if err != nil {
			log.Error("Failed to drop influx database with error: ", err.Error())
@@ -318,7 +325,51 @@ func (gc *GarbageCollector) gcInfluxData() {
	}
}

func getResponseValues(response *influx.Response) ([]map[string]interface{}, error) {
func (gc *GarbageCollector) getInfluxDbNames() (map[string]bool, error) {
	dbNameMap := make(map[string]bool)

	q := influx.NewQuery("SHOW DATABASES", "", "")
	response, err := (*gc.influxClient).Query(q)
	if err != nil {
		return nil, err
	}
	values, err := gc.getResponseValues(response)
	if err != nil {
		return nil, err
	}
	for _, val := range values {
		if dbName, found := val["name"]; found {
			if dbNameStr, ok := dbName.(string); ok {
				dbNameMap[dbNameStr] = true
			}
		}
	}
	return dbNameMap, nil
}

func (gc *GarbageCollector) getInfluxSandboxNames() (map[string]bool, error) {
	sboxNameMap := make(map[string]bool)

	q := influx.NewQuery("SELECT DISTINCT(sboxname) FROM sbox", "global_sandbox_metrics", "")
	response, err := (*gc.influxClient).Query(q)
	if err != nil {
		return nil, err
	}
	values, err := gc.getResponseValues(response)
	if err != nil {
		return nil, err
	}
	for _, val := range values {
		if dbName, found := val["distinct"]; found {
			if dbNameStr, ok := dbName.(string); ok && dbNameStr != "" {
				sboxNameMap[dbNameStr] = true
			}
		}
	}
	return sboxNameMap, nil
}

func (gc *GarbageCollector) getResponseValues(response *influx.Response) ([]map[string]interface{}, error) {
	values := make([]map[string]interface{}, 0)
	if len(response.Results) > 0 && len(response.Results[0].Series) > 0 {
		row := response.Results[0].Series[0]
+16 −1
Original line number Diff line number Diff line
@@ -100,13 +100,24 @@ const execTableStyles = theme => ({
});

const execTableColumnData = [
  { id: 'name', numeric: false, disablePadding: false, label: 'NAME' },
  {
    id: 'name',
    numeric: false,
    disablePadding: false,
    label: 'NAME'
  },
  {
    id: 'logicalState',
    numeric: false,
    disablePadding: false,
    label: 'STATUS'
  },
  {
    id: 'id',
    numeric: false,
    disablePadding: false,
    label: 'APP INSTANCE ID'
  },
  {
    id: 'serviceMaps',
    numeric: false,
@@ -246,7 +257,11 @@ class ExecTable extends Component {
                            >
                              {n.logicalState}
                            </TableCell>
                            <TableCell component='th' scope='row'>
                              {n.id ? n.id : 'N/A'}
                            </TableCell>
                            <TableCell>
                              {!n.ingressServiceMap && !n.egressServiceMap ? 'N/A' : ''}
                              {n.ingressServiceMap
                                ? _.map(n.ingressServiceMap, sm => {
                                  return (
+17 −1
Original line number Diff line number Diff line
@@ -58,7 +58,8 @@ import {
  PAGE_HOME_INDEX,
  PAGE_CONFIGURE_INDEX,
  IDC_DIALOG_SIGN_IN,
  IDC_DIALOG_SESSION_TERMINATED
  IDC_DIALOG_SESSION_TERMINATED,
  ELEMENT_TYPE_EDGE_APP
} from '../meep-constants';

import {
@@ -112,6 +113,8 @@ import {

import {
  FIELD_CONNECTIVITY_MODEL,
  FIELD_TYPE,
  FIELD_IMAGE,
  getElemByName,
  getElemFieldVal
} from '../util/elem-utils';
@@ -335,6 +338,19 @@ class MeepContainer extends Component {
      .get(`${basepathMonEngine}/states?long=true&type=scenario&sandbox=${this.props.sandbox}`)
      .then(res => {
        var scenarioPodsPhases = res.data.podStatus;

        // Add app instance ID for Edge Apps
        if (this.props.exec && this.props.exec.table && this.props.exec.table.entries) {
          for (var i in scenarioPodsPhases) {
            var scenarioPod = scenarioPodsPhases[i];
            var elem = getElemByName(this.props.exec.table.entries, scenarioPod.name);
            let elemType = getElemFieldVal(elem, FIELD_TYPE);
            let elemImage = getElemFieldVal(elem, FIELD_IMAGE);
            if (elem && elemType === ELEMENT_TYPE_EDGE_APP && !elemImage.endsWith('meep-app-enablement')) {
              scenarioPodsPhases[i].id = elem.id;
            }
          }
        }
        this.props.changeScenarioPodsPhases(scenarioPodsPhases);
      })
      .catch(() => {