Skip to content

Commit

Permalink
Merge pull request open-horizon#685 from naphelps/issue-676
Browse files Browse the repository at this point in the history
Issue 676: Added isNamespaceScoped attribute to Nodes.
  • Loading branch information
naphelps committed Jul 11, 2023
2 parents 5e25a7c + f6a51c5 commit 45ac736
Show file tree
Hide file tree
Showing 138 changed files with 1,380 additions and 903 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [2.116.0] - 2023-07-11
- Issue 676: Added `isNamespaceScoped` attribute to Nodes.
- Reorganized table package object source for Nodes and related.
- SBT 1.9.0 -> 1.9.2

## [2.115.3] - 2023-07-07
- Issue 675: Node tokens can be changed by all User types, and public keys can only be [un]set without changing keys by Nodes.

Expand Down
2 changes: 1 addition & 1 deletion docs/openapi-3-developer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name" : "Apache License Version 2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0"
},
"version" : "2.115.3"
"version" : "2.116.0"
},
"externalDocs" : {
"description" : "Open-horizon ExchangeAPI",
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi-3-user.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name" : "Apache License Version 2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0"
},
"version" : "2.115.3"
"version" : "2.116.0"
},
"externalDocs" : {
"description" : "Open-horizon ExchangeAPI",
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.0
sbt.version=1.9.2
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.115.3
2.116.0
2 changes: 1 addition & 1 deletion src/main/scala/org/openhorizon/exchangeapi/AuthCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import scala.concurrent.duration._
import org.openhorizon.exchangeapi.auth._
import com.google.common.cache.CacheBuilder
import org.openhorizon.exchangeapi
import org.openhorizon.exchangeapi.table.NodesTQ
import org.openhorizon.exchangeapi.table.node.NodesTQ
import scalacache._
import scalacache.guava.GuavaCache
import scalacache.modes.try_._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import ch.megard.akka.http.cors.scaladsl.settings.CorsSettings
import org.openhorizon.exchangeapi.route.administration.{AdminRoutes, ClearAuthCache, Configuration, DropDatabase, HashPassword, InitializeDatabase, OrganizationStatus, Reload, Status, Version}
import org.openhorizon.exchangeapi.route.agreementbot.{AgbotsRoutes, Agreement, AgreementBot, AgreementBots, Agreements, DeploymentPattern, DeploymentPatterns, DeploymentPolicies, DeploymentPolicy, Heartbeat, Message, Messages}
import org.openhorizon.exchangeapi.table
import org.openhorizon.exchangeapi.table.{AgbotMsgsTQ, ExchangePostgresProfile, NodeMsgsTQ, ResourceChangesTQ}
import org.openhorizon.exchangeapi.table.{AgbotMsgsTQ, ExchangePostgresProfile, ResourceChangesTQ}
import com.typesafe.config.ConfigFactory
import org.json4s._
import org.openhorizon.exchangeapi.route.administration.dropdatabase.Token
Expand All @@ -52,6 +52,7 @@ import org.openhorizon.exchangeapi.route.nodegroup.NodeGroupRoutes
import org.openhorizon.exchangeapi.route.organization.OrgsRoutes
import org.openhorizon.exchangeapi.route.service.ServicesRoutes
import org.openhorizon.exchangeapi.route.user.UsersRoutes
import org.openhorizon.exchangeapi.table.node.message.NodeMsgsTQ
import slick.jdbc.TransactionIsolation.Serializable

import java.io.{FileInputStream, InputStream}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package org.openhorizon.exchangeapi

import akka.event.LoggingAdapter
import org.openhorizon.exchangeapi.ExchangeApiApp.system
import org.openhorizon.exchangeapi.table.node.NodesTQ
import org.openhorizon.exchangeapi.table.node.agreement.NodeAgreementsTQ
import org.openhorizon.exchangeapi.table.node.deploymentpolicy.NodePolicyTQ
import org.openhorizon.exchangeapi.table.node.error.NodeErrorTQ
import org.openhorizon.exchangeapi.table.node.group.NodeGroupTQ
import org.openhorizon.exchangeapi.table.node.group.assignment.NodeGroupAssignmentTQ
import org.openhorizon.exchangeapi.table.node.managementpolicy.status.NodeMgmtPolStatuses
import org.openhorizon.exchangeapi.table.node.message.NodeMsgsTQ
import org.openhorizon.exchangeapi.table.node.status.NodeStatusTQ
import org.openhorizon.exchangeapi.table.service.SearchServiceTQ
import slick.jdbc.PostgresProfile.api._

import scala.concurrent.ExecutionContext
import org.openhorizon.exchangeapi.table.{AgbotAgreementsTQ, AgbotBusinessPolsTQ, AgbotMsgsTQ, AgbotPatternsTQ, AgbotsTQ, AgentCertificateVersionsTQ, AgentConfigurationVersionsTQ, AgentSoftwareVersionsTQ, AgentVersionsChangedTQ, BusinessPoliciesTQ, ManagementPoliciesTQ, NodeAgreementsTQ, NodeErrorTQ, NodeGroupAssignmentTQ, NodeGroupTQ, NodeMgmtPolStatuses, NodeMsgsTQ, NodePolicyTQ, NodeStatusTQ, NodesTQ, OrgsTQ, PatternKeysTQ, PatternsTQ, ResourceChangesTQ, SchemaRow, SchemaTQ, SearchOffsetPolicyTQ, ServiceDockAuthsTQ, ServiceKeysTQ, ServicePolicyTQ, ServicesTQ, UsersTQ}
import org.openhorizon.exchangeapi.table.{AgbotAgreementsTQ, AgbotBusinessPolsTQ, AgbotMsgsTQ, AgbotPatternsTQ, AgbotsTQ, AgentCertificateVersionsTQ, AgentConfigurationVersionsTQ, AgentSoftwareVersionsTQ, AgentVersionsChangedTQ, BusinessPoliciesTQ, ManagementPoliciesTQ, OrgsTQ, PatternKeysTQ, PatternsTQ, ResourceChangesTQ, SchemaRow, SchemaTQ, SearchOffsetPolicyTQ, ServiceDockAuthsTQ, ServiceKeysTQ, ServicePolicyTQ, ServicesTQ, UsersTQ}
import org.postgresql.util.PSQLException
import slick.collection.heterogeneous.Zero.+

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import io.swagger.v3.oas.annotations._
import io.swagger.v3.oas.annotations.media.{Content, ExampleObject, Schema}
import io.swagger.v3.oas.annotations.parameters.RequestBody
import jakarta.ws.rs.{GET, POST, Path}
import org.openhorizon.exchangeapi.table.{NodeAgreementsTQ, NodeMsgsTQ, NodesTQ, ResourceChangesTQ}
import org.openhorizon.exchangeapi.table.node.NodesTQ
import org.openhorizon.exchangeapi.table.node.message.NodeMsgsTQ
import org.openhorizon.exchangeapi.table.ResourceChangesTQ
import org.openhorizon.exchangeapi.table.node.agreement.NodeAgreementsTQ
import org.openhorizon.exchangeapi.{Access, ApiRespType, AuthCache, AuthenticationSupport, ExchangeApi, ExchangeApiTables, Role}
import slick.jdbc.PostgresProfile.api._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import de.heikoseeberger.akkahttpjackson.JacksonSupport
import io.swagger.v3.oas.annotations.media.{Content, Schema}
import io.swagger.v3.oas.annotations.{Operation, responses}
import jakarta.ws.rs.{GET, Path}
import org.openhorizon.exchangeapi.table.node.NodesTQ
import org.openhorizon.exchangeapi.{Access, AuthenticationSupport, ExchMsg, HttpCode, TAction}
import org.openhorizon.exchangeapi.table.NodesTQ
import slick.jdbc.PostgresProfile.api._

import scala.concurrent.ExecutionContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package org.openhorizon.exchangeapi.route.administration

import akka.actor.ActorSystem
import akka.event.LoggingAdapter
import akka.http.scaladsl.server.Directives.{complete, get, path, pathPrefix, _}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.{Directives, Route}
import de.heikoseeberger.akkahttpjackson.JacksonSupport
import io.swagger.v3.oas.annotations.media.{Content, Schema}
import io.swagger.v3.oas.annotations.{Operation, responses}
import jakarta.ws.rs.{GET, Path}
import org.checkerframework.checker.units.qual.t
import org.openhorizon.exchangeapi.table.node.NodesTQ
import org.openhorizon.exchangeapi.table.node.agreement.NodeAgreementsTQ
import org.openhorizon.exchangeapi.table.node.message.NodeMsgsTQ
import org.openhorizon.exchangeapi.{Access, AuthenticationSupport, ExchMsg, HttpCode, TAction}
import org.openhorizon.exchangeapi.table.{AgbotAgreementsTQ, AgbotMsgsTQ, AgbotsTQ, NodeAgreementsTQ, NodeMsgsTQ, NodesTQ, SchemaTQ, UsersTQ}
import org.openhorizon.exchangeapi.table.{AgbotAgreementsTQ, AgbotMsgsTQ, AgbotsTQ, SchemaTQ, UsersTQ}
import slick.jdbc.PostgresProfile.api._

import scala.concurrent.ExecutionContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import io.swagger.v3.oas.annotations.{Operation, Parameter, responses}
import jakarta.ws.rs.{GET, POST, Path}
import org.checkerframework.checker.units.qual.t
import org.openhorizon.exchangeapi.auth.DBProcessingError
import org.openhorizon.exchangeapi.table.node.NodesTQ
import org.openhorizon.exchangeapi.{Access, ApiRespType, ApiResponse, ApiTime, AuthenticationSupport, ExchConfig, ExchMsg, ExchangePosgtresErrorHandling, HttpCode, Identity, OrgAndId, TAgbot}
import org.openhorizon.exchangeapi.table.{AgbotMsg, AgbotMsgRow, AgbotMsgsTQ, NodesTQ, ResChangeCategory, ResChangeOperation, ResChangeResource, ResourceChange}
import org.openhorizon.exchangeapi.table.{AgbotMsg, AgbotMsgRow, AgbotMsgsTQ, ResChangeCategory, ResChangeOperation, ResChangeResource, ResourceChange}
import slick.jdbc.PostgresProfile.api._

import scala.concurrent.ExecutionContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import org.openhorizon.exchangeapi.auth._
import org.openhorizon.exchangeapi.route.node.{PatternNodeResponse, PostPatternSearchResponse}
import org.openhorizon.exchangeapi.route.organization.{NodeHealthHashElement, PostNodeHealthRequest, PostNodeHealthResponse}
import org.openhorizon.exchangeapi.table._
import org.openhorizon.exchangeapi.table.node.agreement.NodeAgreementsTQ
import org.openhorizon.exchangeapi.table.node.{NodeType, NodesTQ}
import org.openhorizon.exchangeapi.{Access, ApiRespType, ApiResponse, ApiTime, AuthCache, AuthenticationSupport, ExchConfig, ExchMsg, ExchangePosgtresErrorHandling, HttpCode, IUser, Nth, OrgAndId, RouteUtils, TNode, TPattern, Version, auth}
import slick.jdbc.PostgresProfile.api._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import org.json4s.jackson.Serialization.write
import org.json4s.{DefaultFormats, Formats}
import org.openhorizon.exchangeapi.auth.DBProcessingError
import org.openhorizon.exchangeapi.table._
import org.openhorizon.exchangeapi.table.node.agreement.NodeAgreementsTQ
import org.openhorizon.exchangeapi.table.node.{NodeType, NodesTQ}
import org.openhorizon.exchangeapi.{Access, ApiRespType, ApiResponse, ApiTime, AuthCache, AuthenticationSupport, ExchConfig, ExchMsg, ExchangePosgtresErrorHandling, HttpCode, IUser, Nth, OrgAndId, TBusiness, TNode, Version}
import slick.jdbc.PostgresProfile.api._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.openhorizon.exchangeapi.route.node

import org.openhorizon.exchangeapi.table.NodeAgreement
import org.openhorizon.exchangeapi.table.node.agreement.NodeAgreement

/** Output format for GET /orgs/{orgid}/nodes/{id}/agreements */
final case class GetNodeAgreementsResponse(agreements: Map[String,NodeAgreement], lastIndex: Int)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.openhorizon.exchangeapi.route.node

import org.openhorizon.exchangeapi.table.NodeMsg
import org.openhorizon.exchangeapi.table.node.message.NodeMsg

/** Response for GET /orgs/{orgid}/nodes/{id}/msgs */
final case class GetNodeMsgsResponse(messages: List[NodeMsg], lastIndex: Int)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.openhorizon.exchangeapi.route.node

import org.openhorizon.exchangeapi.table.Node
import org.openhorizon.exchangeapi.table.node.Node

/** Output format for GET /orgs/{orgid}/nodes */
final case class GetNodesResponse(nodes: Map[String,Node], lastIndex: Int)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.openhorizon.exchangeapi.route.node

import org.openhorizon.exchangeapi.ExchMsg
import org.openhorizon.exchangeapi.table.NodeType
import org.openhorizon.exchangeapi.table.node.NodeType

object GetNodesUtils {
def getNodesProblem(nodetype: Option[String]): Option[String] = {
Expand Down
29 changes: 22 additions & 7 deletions src/main/scala/org/openhorizon/exchangeapi/route/node/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.openhorizon.exchangeapi.route.node
import akka.actor.ActorSystem
import akka.event.LoggingAdapter
import akka.http.scaladsl.model.{StatusCode, StatusCodes}
import akka.http.scaladsl.server.Directives.{as, complete, entity, get, patch, path, _}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.PathMatchers.Segment
import akka.http.scaladsl.server.Route
import de.heikoseeberger.akkahttpjackson.JacksonSupport
Expand All @@ -17,9 +17,12 @@ import org.json4s.native.Serialization.write
import org.openhorizon.exchangeapi.ApiTime.fixFormatting
import org.openhorizon.exchangeapi.ExchangeApiApp.{exchAuth, validateWithMsg}
import org.openhorizon.exchangeapi.auth.{AccessDeniedException, BadInputException, DBProcessingError, ResourceNotFoundException}
import org.openhorizon.exchangeapi.table.node.group.NodeGroupTQ
import org.openhorizon.exchangeapi.table.node.group.assignment.NodeGroupAssignmentTQ
import org.openhorizon.exchangeapi.table.node.{NodeType, NodesTQ}
import org.openhorizon.exchangeapi.table.service.{SearchServiceKey, SearchServiceTQ}
import org.openhorizon.exchangeapi.table.{NodeGroupAssignmentTQ, NodeGroupTQ, NodeType, NodesTQ, OrgLimits, OrgsTQ, PatternRow, Patterns, PatternsTQ, ResChangeCategory, ResChangeOperation, ResChangeResource, ResourceChange, ResourceChangeRow, ResourceChangesTQ, ServicesTQ}
import org.openhorizon.exchangeapi.{Access, ApiRespType, ApiResponse, ApiTime, AuthCache, AuthRoles, AuthenticationSupport, ExchConfig, ExchMsg, ExchangePosgtresErrorHandling, HttpCode, IUser, Identity, Nth, OrgAndId, Password, TNode, VersionRange}
import org.openhorizon.exchangeapi.table.{OrgLimits, OrgsTQ, PatternRow, Patterns, PatternsTQ, ResChangeCategory, ResChangeOperation, ResChangeResource, ResourceChange, ResourceChangeRow, ResourceChangesTQ, ServicesTQ}
import org.openhorizon.exchangeapi.{Access, ApiRespType, ApiResponse, ApiTime, AuthCache, AuthRoles, AuthenticationSupport, ExchConfig, ExchMsg, ExchangePosgtresErrorHandling, HttpCode, IUser, Identity, Nth, OrgAndId, Password, TNode, VersionRange, table}
import slick.dbio.DBIO
import slick.jdbc.PostgresProfile.api._
import slick.lifted.{Compiled, CompiledExecutable}
Expand Down Expand Up @@ -169,7 +172,8 @@ trait Node extends JacksonSupport with AuthenticationSupport {
},
"ha_group": "groupName",
"lastUpdated": "string",
"clusterNamespace": "MyNamespace"
"clusterNamespace": "MyNamespace",
"isNamespaceScoped": false
}
},
"lastIndex": 0
Expand Down Expand Up @@ -207,7 +211,7 @@ trait Node extends JacksonSupport with AuthenticationSupport {
logger.debug("GET /orgs/" + organization + "/nodes/" + node + " result: " + list.size)
if (list.nonEmpty) {
//val nodes = NodesTQ.parseJoin(ident.isSuperUser, list)
val nodes: Map[String, org.openhorizon.exchangeapi.table.Node] = list.map(e => e._1.id -> e._1.toNode(ident.isSuperUser, e._2)).toMap
val nodes: Map[String, table.node.Node] = list.map(e => e._1.id -> e._1.toNode(ident.isSuperUser, e._2)).toMap
(HttpCode.OK, GetNodesResponse(nodes, 0))
} else {
(HttpCode.NOT_FOUND, ApiResponse(ApiRespType.NOT_FOUND, ExchMsg.translate("not.found"))) // validateAccessToNode() will return ApiRespType.NOT_FOUND to the client so do that here for consistency
Expand Down Expand Up @@ -274,7 +278,8 @@ trait Node extends JacksonSupport with AuthenticationSupport {
"maxInterval": 120,
"intervalAdjustment": 10
},
"clusterNamespace": "MyNamespace"
"clusterNamespace": "MyNamespace",
"isNamespaceScoped": false
}
"""
)
Expand All @@ -301,6 +306,7 @@ trait Node extends JacksonSupport with AuthenticationSupport {
val attributeExistence: Seq[(String, Boolean)] =
Seq(("arch",reqBody.arch.isDefined),
("clusterNamespace", reqBody.clusterNamespace.isDefined),
("isNamespaceScoped", reqBody.isNamespaceScoped.isDefined),
("heartbeatIntervals", reqBody.heartbeatIntervals.isDefined),
("msgEndPoint", reqBody.msgEndPoint.isDefined),
("name", reqBody.name.isDefined),
Expand Down Expand Up @@ -499,6 +505,14 @@ trait Node extends JacksonSupport with AuthenticationSupport {
.atZone(ZoneId.of("UTC"))
.withZoneSameInstant(ZoneId.of("UTC"))
.toString)))
else if (validAttribute == "isNamespaceScoped")
Compiled(NodesTQ.getNode(resource)
.map(node => (node.isNamespaceScoped, node.lastUpdated)))
.update((reqBody.isNamespaceScoped.get,
fixFormatting(changeTimestamp.toInstant
.atZone(ZoneId.of("UTC"))
.withZoneSameInstant(ZoneId.of("UTC"))
.toString)))
else
Compiled(NodesTQ.getNode(resource)
.map(node =>
Expand Down Expand Up @@ -648,7 +662,8 @@ trait Node extends JacksonSupport with AuthenticationSupport {
"maxInterval": 120,
"intervalAdjustment": 10
},
"clusterNamespace": "MyNamespace"
"clusterNamespace": "MyNamespace",
"isNamespaceScoped": false
}
"""
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.openhorizon.exchangeapi.route.node

import org.openhorizon.exchangeapi.StrConstants
import org.openhorizon.exchangeapi.table.{NodeHeartbeatIntervals, OneProperty, OneService, OneUserInputService, RegService}
import org.openhorizon.exchangeapi.table.node.{NodeHeartbeatIntervals, OneService, RegService}
import org.openhorizon.exchangeapi.table.{OneProperty, OneUserInputService}

case class NodeDetails(arch: Option[String] = None,
connectivity: Option[Map[String, Boolean]] = None,
Expand Down Expand Up @@ -29,4 +30,5 @@ case class NodeDetails(arch: Option[String] = None,
token: String = StrConstants.hiddenPw,
userInput: Option[List[OneUserInputService]] = None,
ha_group: Option[String] = None,
clusterNamespace: Option[String] = None)
clusterNamespace: Option[String] = None,
isNamespaceScoped: Boolean = false)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openhorizon.exchangeapi.route.node

import org.openhorizon.exchangeapi.table.{OneUserInputService, RegService}
import org.openhorizon.exchangeapi.table.OneUserInputService
import org.openhorizon.exchangeapi.table.node.RegService

final case class NodeResponse(id: String,
name: String,
Expand All @@ -9,4 +10,5 @@ final case class NodeResponse(id: String,
msgEndPoint: String,
publicKey: String,
arch: String,
clusterNamespace: String)
clusterNamespace: String,
isNamespaceScoped: Boolean = false)
Loading

0 comments on commit 45ac736

Please sign in to comment.