diff --git a/CHANGELOG.md b/CHANGELOG.md index 953afd45ff..1b43f5645f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added an optional readiness check service to cdn-in-a-box that exits successfully when it is able to get a `200 OK` from all delivery services - [Flexible Topologies (in progress)](https://github.com/apache/trafficcontrol/blob/master/blueprints/flexible-topologies.md) - Traffic Ops: Added an API 3.0 endpoint, /api/3.0/topologies, to create, read, update and delete flexible topologies. + - Traffic Ops: Added new `topology` field to the /api/3.0/deliveryservices APIs - Traffic Ops: Added support for `topology` query parameter to `GET /api/3.0/cachegroups` to return all cachegroups used in the given topology. - Traffic Portal: Added the ability to create, read, update and delete flexible topologies. + - Traffic Portal: Added the ability to assign topologies to delivery services - Updated /servers/details to use multiple interfaces in API v3 ### Fixed diff --git a/docs/source/api/v3/deliveryservices.rst b/docs/source/api/v3/deliveryservices.rst index 1caff2ae42..a7f8c86d67 100644 --- a/docs/source/api/v3/deliveryservices.rst +++ b/docs/source/api/v3/deliveryservices.rst @@ -44,6 +44,8 @@ Request Structure +--------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------+ | tenant | no | Show only the :term:`Delivery Services` belonging to the :term:`Tenant` identified by this integral, unique identifier | +--------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------+ + | topology | no | Show only the :term:`Delivery Services` assigned to the :term:`Topology` identified by this unique name | + +--------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------+ | type | no | Return only :term:`Delivery Services` of the :term:`Delivery Service` :ref:`ds-types` identified by this integral, unique identifier | +--------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------+ | accessibleTo | no | Return the :term:`Delivery Services` accessible from a :term:`Tenant` *or it's children* identified by this integral, unique identifier | @@ -133,6 +135,7 @@ Response Structure :rangeSliceBlockSize: An integer that defines the byte block size for the ATS Slice Plugin. It can only and must be set if ``rangeRequestHandling`` is set to 3. :sslKeyVersion: This integer indicates the :ref:`ds-ssl-key-version` :tenantId: The integral, unique identifier of the :ref:`ds-tenant` who owns this :term:`Delivery Service` +:topology: The unique name of the :term:`Topology` that this :term:`Delivery Service` is assigned to :trRequestHeaders: If defined, this defines the :ref:`ds-tr-req-headers` used by Traffic Router for this :term:`Delivery Service` :trResponseHeaders: If defined, this defines the :ref:`ds-tr-resp-headers` used by Traffic Router for this :term:`Delivery Service` :type: The :ref:`ds-types` of this :term:`Delivery Service` @@ -234,7 +237,8 @@ Response Structure ], "maxOriginConnections": 0, "ecsEnabled": false, - "rangeSliceBlockSize": null + "rangeSliceBlockSize": null, + "topology": null }]} @@ -304,6 +308,7 @@ Request Structure :rangeSliceBlockSize: An integer that defines the byte block size for the ATS Slice Plugin. It can only and must be set if ``rangeRequestHandling`` is set to 3. It can only be between (inclusive) 262144 (256KB) - 33554432 (32MB). :sslKeyVersion: This integer indicates the :ref:`ds-ssl-key-version` :tenantId: The integral, unique identifier of the :ref:`ds-tenant` who owns this :term:`Delivery Service` +:topology: The unique name of the :term:`Topology` that this :term:`Delivery Service` is assigned to :trRequestHeaders: If defined, this defines the :ref:`ds-tr-req-headers` used by Traffic Router for this :term:`Delivery Service` :trResponseHeaders: If defined, this defines the :ref:`ds-tr-resp-headers` used by Traffic Router for this :term:`Delivery Service` :type: The :ref:`ds-types` of this :term:`Delivery Service` @@ -423,6 +428,7 @@ Response Structure :rangeSliceBlockSize: An integer that defines the byte block size for the ATS Slice Plugin. It can only and must be set if ``rangeRequestHandling`` is set to 3. :sslKeyVersion: This integer indicates the :ref:`ds-ssl-key-version` :tenantId: The integral, unique identifier of the :ref:`ds-tenant` who owns this :term:`Delivery Service` +:topology: The unique name of the :term:`Topology` that this :term:`Delivery Service` is assigned to :trRequestHeaders: If defined, this defines the :ref:`ds-tr-req-headers` used by Traffic Router for this :term:`Delivery Service` :trResponseHeaders: If defined, this defines the :ref:`ds-tr-resp-headers` used by Traffic Router for this :term:`Delivery Service` :type: The :ref:`ds-types` of this :term:`Delivery Service` @@ -520,7 +526,8 @@ Response Structure "signingAlgorithm": null, "tenant": "root", "ecsEnabled": true, - "rangeSliceBlockSize": null + "rangeSliceBlockSize": null, + "topology": null } ]} diff --git a/docs/source/api/v3/deliveryservices_id.rst b/docs/source/api/v3/deliveryservices_id.rst index 93b6136dfd..44ad9afe37 100644 --- a/docs/source/api/v3/deliveryservices_id.rst +++ b/docs/source/api/v3/deliveryservices_id.rst @@ -86,6 +86,7 @@ Request Structure :rangeSliceBlockSize: An integer that defines the byte block size for the ATS Slice Plugin. It can only and must be set if ``rangeRequestHandling`` is set to 3. It can only be between (inclusive) 262144 (256KB) - 33554432 (32MB). :sslKeyVersion: This integer indicates the :ref:`ds-ssl-key-version` :tenantId: The integral, unique identifier of the :ref:`ds-tenant` who owns this :term:`Delivery Service` +:topology: The unique name of the :term:`Topology` that this :term:`Delivery Service` is assigned to :trRequestHeaders: If defined, this defines the :ref:`ds-tr-req-headers` used by Traffic Router for this :term:`Delivery Service` :trResponseHeaders: If defined, this defines the :ref:`ds-tr-resp-headers` used by Traffic Router for this :term:`Delivery Service` :typeId: The integral, unique identifier of the :ref:`ds-types` of this :term:`Delivery Service` diff --git a/docs/source/api/v3/deliveryservices_id_safe.rst b/docs/source/api/v3/deliveryservices_id_safe.rst index f249615589..bc50684c28 100644 --- a/docs/source/api/v3/deliveryservices_id_safe.rst +++ b/docs/source/api/v3/deliveryservices_id_safe.rst @@ -129,6 +129,7 @@ Response Structure :rangeSliceBlockSize: An integer that defines the byte block size for the ATS Slice Plugin. It can only and must be set if ``rangeRequestHandling`` is set to 3. :sslKeyVersion: This integer indicates the :ref:`ds-ssl-key-version` :tenantId: The integral, unique identifier of the :ref:`ds-tenant` who owns this :term:`Delivery Service` +:topology: The unique name of the :term:`Topology` that this :term:`Delivery Service` is assigned to :trRequestHeaders: If defined, this defines the :ref:`ds-tr-req-headers` used by Traffic Router for this :term:`Delivery Service` :trResponseHeaders: If defined, this defines the :ref:`ds-tr-resp-headers` used by Traffic Router for this :term:`Delivery Service` :type: The :ref:`ds-types` of this :term:`Delivery Service` @@ -233,7 +234,8 @@ Response Structure ], "maxOriginConnections": 0, "ecsEnabled": false, - "rangeSliceBlockSize": null + "rangeSliceBlockSize": null, + "topology": null } ]} diff --git a/docs/source/api/v3/servers_id_deliveryservices.rst b/docs/source/api/v3/servers_id_deliveryservices.rst index 5fa2ed6431..d95ae00800 100644 --- a/docs/source/api/v3/servers_id_deliveryservices.rst +++ b/docs/source/api/v3/servers_id_deliveryservices.rst @@ -135,6 +135,7 @@ Response Structure :rangeSliceBlockSize: An integer that defines the byte block size for the ATS Slice Plugin. It can only and must be set if ``rangeRequestHandling`` is set to 3. :sslKeyVersion: This integer indicates the :ref:`ds-ssl-key-version` :tenantId: The integral, unique identifier of the :ref:`ds-tenant` who owns this :term:`Delivery Service` +:topology: The unique name of the :term:`Topology` that this :term:`Delivery Service` is assigned to :trRequestHeaders: If defined, this defines the :ref:`ds-tr-req-headers` used by Traffic Router for this :term:`Delivery Service` :trResponseHeaders: If defined, this defines the :ref:`ds-tr-resp-headers` used by Traffic Router for this :term:`Delivery Service` :type: The :ref:`ds-types` of this :term:`Delivery Service` @@ -236,7 +237,8 @@ Response Structure ], "maxOriginConnections": 0, "ecsEnabled": false, - "rangeSliceBlockSize": null + "rangeSliceBlockSize": null, + "topology": null }]} diff --git a/lib/go-tc/deliveryservices.go b/lib/go-tc/deliveryservices.go index bb1a54dc84..d8bc0d299d 100644 --- a/lib/go-tc/deliveryservices.go +++ b/lib/go-tc/deliveryservices.go @@ -159,9 +159,14 @@ type DeliveryServiceV11 struct { XMLID string `json:"xmlId"` } -type DeliveryServiceNullableV15 DeliveryServiceNullable // this type alias should always alias the latest minor version of the deliveryservices endpoints +type DeliveryServiceNullableV30 DeliveryServiceNullable // this type alias should always alias the latest minor version of the deliveryservices endpoints type DeliveryServiceNullable struct { + DeliveryServiceNullableV15 + Topology *string `json:"topology" db:"topology"` +} + +type DeliveryServiceNullableV15 struct { DeliveryServiceNullableV14 EcsEnabled bool `json:"ecsEnabled" db:"ecs_enabled"` RangeSliceBlockSize *int `json:"rangeSliceBlockSize" db:"range_slice_block_size"` @@ -415,6 +420,14 @@ func (ds *DeliveryServiceNullable) validateTypeFields(tx *sql.Tx) error { validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName))), "rangeRequestHandling": validation.Validate(ds.RangeRequestHandling, validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName))), + "topology": validation.Validate(ds, + validation.By(func(dsi interface{}) error { + ds := dsi.(*DeliveryServiceNullable) + if ds.Topology != nil && DSType(typeName).IsSteering() { + return fmt.Errorf("steering deliveryservice types cannot be assigned to a topology") + } + return nil + })), } toErrs := tovalidate.ToErrors(errs) if len(toErrs) > 0 { diff --git a/traffic_ops/ort/atstccfg/cfgfile/cfgfile_test.go b/traffic_ops/ort/atstccfg/cfgfile/cfgfile_test.go index 5c41360eb7..1e8cb639d3 100644 --- a/traffic_ops/ort/atstccfg/cfgfile/cfgfile_test.go +++ b/traffic_ops/ort/atstccfg/cfgfile/cfgfile_test.go @@ -210,94 +210,86 @@ func randDS() *tc.DeliveryServiceNullable { deepCachingTypeNever := tc.DeepCachingTypeNever dsTypeHTTP := tc.DSTypeHTTP protocol := tc.DSProtocolHTTP - return &tc.DeliveryServiceNullable{ - EcsEnabled: *randBool(), - RangeSliceBlockSize: randInt(), - DeliveryServiceNullableV14: tc.DeliveryServiceNullableV14{ - ConsistentHashRegex: randStr(), - ConsistentHashQueryParams: []string{ - *randStr(), - *randStr(), - }, - MaxOriginConnections: randInt(), - DeliveryServiceNullableV13: tc.DeliveryServiceNullableV13{ - DeepCachingType: &deepCachingTypeNever, - FQPacingRate: randInt(), - SigningAlgorithm: randStr(), - Tenant: randStr(), - TRResponseHeaders: randStr(), - TRRequestHeaders: randStr(), - DeliveryServiceNullableV12: tc.DeliveryServiceNullableV12{ - DeliveryServiceNullableV11: tc.DeliveryServiceNullableV11{ - Active: randBool(), - AnonymousBlockingEnabled: randBool(), - CacheURL: randStr(), - CCRDNSTTL: randInt(), - CDNID: randInt(), - CDNName: randStr(), - CheckPath: randStr(), - DisplayName: randStr(), - DNSBypassCNAME: randStr(), - DNSBypassIP: randStr(), - DNSBypassIP6: randStr(), - DNSBypassTTL: randInt(), - DSCP: randInt(), - EdgeHeaderRewrite: randStr(), - GeoLimit: randInt(), - GeoLimitCountries: randStr(), - GeoLimitRedirectURL: randStr(), - GeoProvider: randInt(), - GlobalMaxMBPS: randInt(), - GlobalMaxTPS: randInt(), - HTTPBypassFQDN: randStr(), - ID: randInt(), - InfoURL: randStr(), - InitialDispersion: randInt(), - IPV6RoutingEnabled: randBool(), - LastUpdated: &tc.TimeNoMod{Time: time.Now()}, - LogsEnabled: randBool(), - LongDesc: randStr(), - LongDesc1: randStr(), - LongDesc2: randStr(), - MatchList: &[]tc.DeliveryServiceMatch{ - tc.DeliveryServiceMatch{ - Type: tc.DSMatchTypeHostRegex, - SetNumber: 0, - Pattern: `\.*foo\.*`, - }, - }, - MaxDNSAnswers: randInt(), - MidHeaderRewrite: randStr(), - MissLat: randFloat64(), - MissLong: randFloat64(), - MultiSiteOrigin: randBool(), - OriginShield: randStr(), - OrgServerFQDN: randStr(), - ProfileDesc: randStr(), - ProfileID: randInt(), - ProfileName: randStr(), - Protocol: &protocol, - QStringIgnore: randInt(), - RangeRequestHandling: randInt(), - RegexRemap: randStr(), - RegionalGeoBlocking: randBool(), - RemapText: randStr(), - RoutingName: randStr(), - Signed: *randBool(), - SSLKeyVersion: randInt(), - TenantID: randInt(), - Type: &dsTypeHTTP, - TypeID: randInt(), - XMLID: randStr(), - ExampleURLs: []string{ - *randStr(), - *randStr(), - }, - }, - }, - }, + ds := tc.DeliveryServiceNullable{} + ds.EcsEnabled = *randBool() + ds.RangeSliceBlockSize = randInt() + ds.ConsistentHashRegex = randStr() + ds.ConsistentHashQueryParams = []string{ + *randStr(), + *randStr(), + } + ds.MaxOriginConnections = randInt() + ds.DeepCachingType = &deepCachingTypeNever + ds.FQPacingRate = randInt() + ds.SigningAlgorithm = randStr() + ds.Tenant = randStr() + ds.TRResponseHeaders = randStr() + ds.TRRequestHeaders = randStr() + ds.Active = randBool() + ds.AnonymousBlockingEnabled = randBool() + ds.CacheURL = randStr() + ds.CCRDNSTTL = randInt() + ds.CDNID = randInt() + ds.CDNName = randStr() + ds.CheckPath = randStr() + ds.DisplayName = randStr() + ds.DNSBypassCNAME = randStr() + ds.DNSBypassIP = randStr() + ds.DNSBypassIP6 = randStr() + ds.DNSBypassTTL = randInt() + ds.DSCP = randInt() + ds.EdgeHeaderRewrite = randStr() + ds.GeoLimit = randInt() + ds.GeoLimitCountries = randStr() + ds.GeoLimitRedirectURL = randStr() + ds.GeoProvider = randInt() + ds.GlobalMaxMBPS = randInt() + ds.GlobalMaxTPS = randInt() + ds.HTTPBypassFQDN = randStr() + ds.ID = randInt() + ds.InfoURL = randStr() + ds.InitialDispersion = randInt() + ds.IPV6RoutingEnabled = randBool() + ds.LastUpdated = &tc.TimeNoMod{Time: time.Now()} + ds.LogsEnabled = randBool() + ds.LongDesc = randStr() + ds.LongDesc1 = randStr() + ds.LongDesc2 = randStr() + ds.MatchList = &[]tc.DeliveryServiceMatch{ + { + Type: tc.DSMatchTypeHostRegex, + SetNumber: 0, + Pattern: `\.*foo\.*`, }, } + ds.MaxDNSAnswers = randInt() + ds.MidHeaderRewrite = randStr() + ds.MissLat = randFloat64() + ds.MissLong = randFloat64() + ds.MultiSiteOrigin = randBool() + ds.OriginShield = randStr() + ds.OrgServerFQDN = randStr() + ds.ProfileDesc = randStr() + ds.ProfileID = randInt() + ds.ProfileName = randStr() + ds.Protocol = &protocol + ds.QStringIgnore = randInt() + ds.RangeRequestHandling = randInt() + ds.RegexRemap = randStr() + ds.RegionalGeoBlocking = randBool() + ds.RemapText = randStr() + ds.RoutingName = randStr() + ds.Signed = *randBool() + ds.SSLKeyVersion = randInt() + ds.TenantID = randInt() + ds.Type = &dsTypeHTTP + ds.TypeID = randInt() + ds.XMLID = randStr() + ds.ExampleURLs = []string{ + *randStr(), + *randStr(), + } + return &ds } func randServer() *tc.Server { diff --git a/traffic_ops/testing/api/v3/cachegroupsdeliveryservices_test.go b/traffic_ops/testing/api/v3/cachegroupsdeliveryservices_test.go index 8123d301e1..0e59e3bed5 100644 --- a/traffic_ops/testing/api/v3/cachegroupsdeliveryservices_test.go +++ b/traffic_ops/testing/api/v3/cachegroupsdeliveryservices_test.go @@ -20,7 +20,7 @@ import ( ) func TestCacheGroupsDeliveryServices(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices, CacheGroupsDeliveryServices}, func() {}) + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, CacheGroupsDeliveryServices}, func() {}) } // TODO this is the name hard-coded in the create servers test; change to be dynamic diff --git a/traffic_ops/testing/api/v3/cdnfederations_test.go b/traffic_ops/testing/api/v3/cdnfederations_test.go index 5caa730682..242bfdc381 100644 --- a/traffic_ops/testing/api/v3/cdnfederations_test.go +++ b/traffic_ops/testing/api/v3/cdnfederations_test.go @@ -26,14 +26,14 @@ import ( var fedIDs []int func TestCDNFederations(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Parameters, Tenants, DeliveryServices, CDNFederations}, func() { + WithObjs(t, []TCObj{CDNs, Types, Parameters, Tenants, CacheGroups, Topologies, DeliveryServices, CDNFederations}, func() { UpdateTestCDNFederations(t) GetTestCDNFederations(t) }) } func TestFederationFederationResolvers(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Parameters, Tenants, DeliveryServices, CDNFederations, FederationResolvers}, func() { + WithObjs(t, []TCObj{CDNs, Types, Parameters, Tenants, CacheGroups, Topologies, DeliveryServices, CDNFederations, FederationResolvers}, func() { AssignTestFederationFederationResolvers(t) GetTestFederationFederationResolvers(t) }) diff --git a/traffic_ops/testing/api/v3/crconfig_test.go b/traffic_ops/testing/api/v3/crconfig_test.go index 6396d6464c..a01b894f68 100644 --- a/traffic_ops/testing/api/v3/crconfig_test.go +++ b/traffic_ops/testing/api/v3/crconfig_test.go @@ -24,7 +24,7 @@ import ( ) func TestCRConfig(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices}, func() { UpdateTestCRConfigSnapshot(t) SnapshotTestCDNbyName(t) SnapshotTestCDNbyInvalidName(t) diff --git a/traffic_ops/testing/api/v3/deliveryservices_required_capabilities_test.go b/traffic_ops/testing/api/v3/deliveryservices_required_capabilities_test.go index 5f3383e301..d3283a56f3 100644 --- a/traffic_ops/testing/api/v3/deliveryservices_required_capabilities_test.go +++ b/traffic_ops/testing/api/v3/deliveryservices_required_capabilities_test.go @@ -25,7 +25,7 @@ import ( ) func TestDeliveryServicesRequiredCapabilities(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, DeliveryServices, DeliveryServicesRequiredCapabilities}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, Topologies, DeliveryServices, DeliveryServicesRequiredCapabilities}, func() { InvalidDeliveryServicesRequiredCapabilityAddition(t) GetTestDeliveryServicesRequiredCapabilities(t) }) diff --git a/traffic_ops/testing/api/v3/deliveryservices_test.go b/traffic_ops/testing/api/v3/deliveryservices_test.go index b0e3a0a469..bddb575ad0 100644 --- a/traffic_ops/testing/api/v3/deliveryservices_test.go +++ b/traffic_ops/testing/api/v3/deliveryservices_test.go @@ -30,12 +30,13 @@ import ( ) func TestDeliveryServices(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices}, func() { GetAccessibleToTest(t) UpdateTestDeliveryServices(t) UpdateNullableTestDeliveryServices(t) UpdateDeliveryServiceWithInvalidRemapText(t) UpdateDeliveryServiceWithInvalidSliceRangeRequest(t) + UpdateDeliveryServiceWithInvalidTopology(t) GetTestDeliveryServices(t) DeliveryServiceMinorVersionsTest(t) DeliveryServiceTenancyTest(t) @@ -204,6 +205,28 @@ func UpdateNullableTestDeliveryServices(t *testing.T) { } } +// UpdateDeliveryServiceWithInvalidTopology ensures that a topology cannot be assigned to (CLIENT_)STEERING delivery services. +func UpdateDeliveryServiceWithInvalidTopology(t *testing.T) { + dses, _, err := TOSession.GetDeliveryServicesNullable() + if err != nil { + t.Fatalf("cannot GET Delivery Services: %v", err) + } + + found := false + for _, ds := range dses { + if *ds.Type == tc.DSTypeClientSteering { + found = true + ds.Topology = util.StrPtr("my-topology") + if _, err := TOSession.UpdateDeliveryServiceNullable(strconv.Itoa(*ds.ID), &ds); err == nil { + t.Errorf("assigning topology to CLIENT_STEERING delivery service - expected: error, actual: no error") + } + } + } + if !found { + t.Fatalf("expected at least one CLIENT_STEERING delivery service") + } +} + // UpdateDeliveryServiceWithInvalidRemapText ensures that a delivery service can't be updated with a remap text value with a line break in it. func UpdateDeliveryServiceWithInvalidRemapText(t *testing.T) { firstDS := testData.DeliveryServices[0] diff --git a/traffic_ops/testing/api/v3/deliveryserviceservers_test.go b/traffic_ops/testing/api/v3/deliveryserviceservers_test.go index ce72f7ddc1..1a173dcae9 100644 --- a/traffic_ops/testing/api/v3/deliveryserviceservers_test.go +++ b/traffic_ops/testing/api/v3/deliveryserviceservers_test.go @@ -25,13 +25,13 @@ import ( ) func TestDeliveryServiceServers(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices}, func() { DeleteTestDeliveryServiceServers(t) }) } func TestDeliveryServiceServersWithRequiredCapabilities(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, DeliveryServices, DeliveryServicesRequiredCapabilities, ServerServerCapabilities}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, ServerCapabilities, Topologies, DeliveryServices, DeliveryServicesRequiredCapabilities, ServerServerCapabilities}, func() { CreateTestDeliveryServiceServersWithRequiredCapabilities(t) CreateTestMSODSServerWithReqCap(t) }) diff --git a/traffic_ops/testing/api/v3/deliveryservicesideligible_test.go b/traffic_ops/testing/api/v3/deliveryservicesideligible_test.go index af4132e563..b0ddb9544b 100644 --- a/traffic_ops/testing/api/v3/deliveryservicesideligible_test.go +++ b/traffic_ops/testing/api/v3/deliveryservicesideligible_test.go @@ -20,7 +20,7 @@ import ( ) func TestDeliveryServicesEligible(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices}, func() { GetTestDeliveryServicesEligible(t) }) } diff --git a/traffic_ops/testing/api/v3/deliveryservicesregexes_test.go b/traffic_ops/testing/api/v3/deliveryservicesregexes_test.go index caa443372e..8ed520cfa5 100644 --- a/traffic_ops/testing/api/v3/deliveryservicesregexes_test.go +++ b/traffic_ops/testing/api/v3/deliveryservicesregexes_test.go @@ -24,7 +24,7 @@ import ( ) func TestDeliveryServicesRegexes(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices, DeliveryServicesRegexes}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, DeliveryServicesRegexes}, func() { QueryDSRegexTest(t) }) } diff --git a/traffic_ops/testing/api/v3/federation_users_test.go b/traffic_ops/testing/api/v3/federation_users_test.go index 794c1175aa..ba2f38b734 100644 --- a/traffic_ops/testing/api/v3/federation_users_test.go +++ b/traffic_ops/testing/api/v3/federation_users_test.go @@ -20,7 +20,7 @@ import ( ) func TestFederationUsers(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, DeliveryServices, CDNFederations, FederationUsers}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Topologies, DeliveryServices, CDNFederations, FederationUsers}, func() { CreateTestInvalidFederationUsers(t) GetTestInvalidFederationIDUsers(t) }) diff --git a/traffic_ops/testing/api/v3/federations_test.go b/traffic_ops/testing/api/v3/federations_test.go index f555b6f940..910e770eee 100644 --- a/traffic_ops/testing/api/v3/federations_test.go +++ b/traffic_ops/testing/api/v3/federations_test.go @@ -24,7 +24,7 @@ import ( ) func TestFederations(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, DeliveryServices, CDNFederations}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Topologies, DeliveryServices, CDNFederations}, func() { PostDeleteTestFederationsDeliveryServices(t) GetTestFederations(t) AddFederationResolversForCurrentUserTest(t) diff --git a/traffic_ops/testing/api/v3/jobs_test.go b/traffic_ops/testing/api/v3/jobs_test.go index 9b597e4d01..04b8188ef7 100644 --- a/traffic_ops/testing/api/v3/jobs_test.go +++ b/traffic_ops/testing/api/v3/jobs_test.go @@ -24,7 +24,7 @@ import ( ) func TestJobs(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices}, func() { CreateTestJobs(t) CreateTestInvalidationJobs(t) GetTestJobsQueryParams(t) diff --git a/traffic_ops/testing/api/v3/origins_test.go b/traffic_ops/testing/api/v3/origins_test.go index 0839d42d51..86dcd14511 100644 --- a/traffic_ops/testing/api/v3/origins_test.go +++ b/traffic_ops/testing/api/v3/origins_test.go @@ -27,7 +27,7 @@ import ( ) func TestOrigins(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Users, DeliveryServices, Coordinates, Origins}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Users, Topologies, DeliveryServices, Coordinates, Origins}, func() { UpdateTestOrigins(t) GetTestOrigins(t) NotFoundDeleteTest(t) diff --git a/traffic_ops/testing/api/v3/readonlycannotmodify_test.go b/traffic_ops/testing/api/v3/readonlycannotmodify_test.go index 3c04553bde..eec72220d7 100644 --- a/traffic_ops/testing/api/v3/readonlycannotmodify_test.go +++ b/traffic_ops/testing/api/v3/readonlycannotmodify_test.go @@ -25,7 +25,7 @@ import ( ) func TestReadOnlyCannotModify(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, DeliveryServices, Users}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Topologies, DeliveryServices, Users}, func() { CreateTestCDNWithReadOnlyUser(t) }) } diff --git a/traffic_ops/testing/api/v3/servers_test.go b/traffic_ops/testing/api/v3/servers_test.go index d174ddf744..fc96503c3a 100644 --- a/traffic_ops/testing/api/v3/servers_test.go +++ b/traffic_ops/testing/api/v3/servers_test.go @@ -22,7 +22,7 @@ import ( ) func TestServers(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, DeliveryServices, Servers}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Topologies, DeliveryServices, Servers}, func() { UpdateTestServers(t) GetTestServersDetails(t) GetTestServers(t) diff --git a/traffic_ops/testing/api/v3/servers_to_deliveryservice_assignment_test.go b/traffic_ops/testing/api/v3/servers_to_deliveryservice_assignment_test.go index 775324a574..625e80300d 100644 --- a/traffic_ops/testing/api/v3/servers_to_deliveryservice_assignment_test.go +++ b/traffic_ops/testing/api/v3/servers_to_deliveryservice_assignment_test.go @@ -21,7 +21,7 @@ import ( ) func TestAssignments(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Tenants, DeliveryServices}, func() { + WithObjs(t, []TCObj{CDNs, Types, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Tenants, Topologies, DeliveryServices}, func() { AssignTestDeliveryService(t) AssignIncorrectTestDeliveryService(t) }) diff --git a/traffic_ops/testing/api/v3/serverservercapability_test.go b/traffic_ops/testing/api/v3/serverservercapability_test.go index 2a3c91f7af..adcc789b80 100644 --- a/traffic_ops/testing/api/v3/serverservercapability_test.go +++ b/traffic_ops/testing/api/v3/serverservercapability_test.go @@ -23,7 +23,7 @@ import ( ) func TestServerServerCapabilities(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices, ServerCapabilities, DeliveryServicesRequiredCapabilities, ServerServerCapabilities}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, ServerCapabilities, DeliveryServicesRequiredCapabilities, ServerServerCapabilities}, func() { GetTestServerServerCapabilities(t) }) } diff --git a/traffic_ops/testing/api/v3/staticdnsentries_test.go b/traffic_ops/testing/api/v3/staticdnsentries_test.go index 671ad74940..6863b7efdb 100644 --- a/traffic_ops/testing/api/v3/staticdnsentries_test.go +++ b/traffic_ops/testing/api/v3/staticdnsentries_test.go @@ -18,12 +18,13 @@ package v3 import ( "testing" - tc "github.com/apache/trafficcontrol/lib/go-tc" "reflect" + + tc "github.com/apache/trafficcontrol/lib/go-tc" ) func TestStaticDNSEntries(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices, StaticDNSEntries}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, StaticDNSEntries}, func() { GetTestStaticDNSEntries(t) UpdateTestStaticDNSEntries(t) UpdateTestStaticDNSEntriesInvalidAddress(t) diff --git a/traffic_ops/testing/api/v3/steering_test.go b/traffic_ops/testing/api/v3/steering_test.go index e1a27f25ef..2baefeeab0 100644 --- a/traffic_ops/testing/api/v3/steering_test.go +++ b/traffic_ops/testing/api/v3/steering_test.go @@ -20,7 +20,7 @@ import ( ) func TestSteering(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices, Users, SteeringTargets}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, Users, SteeringTargets}, func() { GetTestSteering(t) }) } diff --git a/traffic_ops/testing/api/v3/steeringtargets_test.go b/traffic_ops/testing/api/v3/steeringtargets_test.go index 0ed42e9c1f..06c40e261b 100644 --- a/traffic_ops/testing/api/v3/steeringtargets_test.go +++ b/traffic_ops/testing/api/v3/steeringtargets_test.go @@ -27,7 +27,7 @@ var SteeringUserSession *client.Session func TestSteeringTargets(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, DeliveryServices, Users, SteeringTargets}, func() { + WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices, Users, SteeringTargets}, func() { GetTestSteeringTargets(t) UpdateTestSteeringTargets(t) }) diff --git a/traffic_ops/testing/api/v3/tc-fixtures.json b/traffic_ops/testing/api/v3/tc-fixtures.json index 9fc1cc2a3c..e8b8612bf1 100644 --- a/traffic_ops/testing/api/v3/tc-fixtures.json +++ b/traffic_ops/testing/api/v3/tc-fixtures.json @@ -704,6 +704,133 @@ "type": "HTTP_LIVE_NATNL", "xmlId": "ds1nat", "anonymousBlockingEnabled": true + }, + { + "active": true, + "cdnName": "cdn1", + "cacheurl": "", + "ccrDnsTtl": 3600, + "checkPath": "", + "consistentHashQueryParams": [], + "deepCachingType": "NEVER", + "displayName": "ds-with-topology", + "dnsBypassCname": null, + "dnsBypassIp": "", + "dnsBypassIp6": "", + "dnsBypassTtl": 30, + "dscp": 40, + "edgeHeaderRewrite": null, + "fqPacingRate": 0, + "geoLimit": 0, + "geoLimitCountries": "", + "geoLimitRedirectURL": null, + "geoProvider": 0, + "globalMaxMbps": 0, + "globalMaxTps": 0, + "httpBypassFqdn": "", + "infoUrl": "TBD", + "initialDispersion": 1, + "ipv6RoutingEnabled": true, + "lastUpdated": "2018-04-06 16:48:51+00", + "logsEnabled": false, + "longDesc": "d s top", + "longDesc1": "ds top", + "longDesc2": "ds-top", + "matchList": [ + { + "pattern": ".*\\.ds-top\\..*", + "setNumber": 0, + "type": "HOST_REGEXP" + } + ], + "maxDnsAnswers": 0, + "midHeaderRewrite": null, + "missLat": 41.881944, + "missLong": -87.627778, + "multiSiteOrigin": false, + "orgServerFqdn": "http://origin.topology.example.net", + "originShield": null, + "profileDescription": null, + "profileName": null, + "protocol": 2, + "qstringIgnore": 1, + "rangeRequestHandling": 0, + "regexRemap": null, + "regionalGeoBlocking": false, + "remapText": null, + "routingName": "cdn", + "signed": false, + "signingAlgorithm": null, + "sslKeyVersion": 0, + "tenant": "tenant1", + "tenantName": "tenant1", + "type": "HTTP_LIVE_NATNL", + "xmlId": "ds-top", + "anonymousBlockingEnabled": false, + "topology": "my-topology" + }, + { + "active": true, + "cdnName": "cdn1", + "cacheurl": "", + "ccrDnsTtl": 3600, + "checkPath": "", + "consistentHashQueryParams": [], + "deepCachingType": "NEVER", + "displayName": "ds-client-steering", + "dnsBypassCname": null, + "dnsBypassIp": "", + "dnsBypassIp6": "", + "dnsBypassTtl": 30, + "dscp": 40, + "edgeHeaderRewrite": null, + "fqPacingRate": 0, + "geoLimit": 0, + "geoLimitCountries": "", + "geoLimitRedirectURL": null, + "geoProvider": 0, + "globalMaxMbps": 0, + "globalMaxTps": 0, + "httpBypassFqdn": "", + "infoUrl": "TBD", + "initialDispersion": 1, + "ipv6RoutingEnabled": true, + "lastUpdated": "2018-04-06 16:48:51+00", + "logsEnabled": false, + "longDesc": "d s client-steering", + "longDesc1": "ds client-steering", + "longDesc2": "ds-client-steering", + "matchList": [ + { + "pattern": ".*\\.ds-client-steering\\..*", + "setNumber": 0, + "type": "HOST_REGEXP" + } + ], + "maxDnsAnswers": 0, + "midHeaderRewrite": null, + "missLat": 41.881944, + "missLong": -87.627778, + "multiSiteOrigin": false, + "orgServerFqdn": null, + "originShield": null, + "profileDescription": null, + "profileName": null, + "protocol": 2, + "qstringIgnore": 0, + "rangeRequestHandling": 0, + "regexRemap": null, + "regionalGeoBlocking": false, + "remapText": null, + "routingName": "cdn", + "signed": false, + "signingAlgorithm": null, + "sslKeyVersion": 0, + "tenant": "tenant1", + "tenantName": "tenant1", + "type": "CLIENT_STEERING", + "xmlId": "ds-client-steering", + "anonymousBlockingEnabled": false } ], "deliveryServicesRegexes": [ diff --git a/traffic_ops/testing/api/v3/tenants_test.go b/traffic_ops/testing/api/v3/tenants_test.go index 3dcb232280..33d86665b1 100644 --- a/traffic_ops/testing/api/v3/tenants_test.go +++ b/traffic_ops/testing/api/v3/tenants_test.go @@ -26,12 +26,18 @@ import ( ) func TestTenants(t *testing.T) { - WithObjs(t, []TCObj{Parameters, Tenants}, func() { + WithObjs(t, []TCObj{Tenants}, func() { GetTestTenants(t) UpdateTestTenants(t) }) } +func TestTenantsActive(t *testing.T) { + WithObjs(t, []TCObj{CDNs, Types, Tenants, CacheGroups, Topologies, DeliveryServices, Users}, func() { + UpdateTestTenantsActive(t) + }) +} + func CreateTestTenants(t *testing.T) { for _, ten := range testData.Tenants { resp, err := TOSession.CreateTenant(&ten) @@ -160,38 +166,6 @@ func DeleteTestTenants(t *testing.T) { } } -func TestTenantsActive(t *testing.T) { - CreateTestCDNs(t) - CreateTestTypes(t) - CreateTestTenants(t) - CreateTestParameters(t) - CreateTestProfiles(t) - CreateTestStatuses(t) - CreateTestDivisions(t) - CreateTestRegions(t) - CreateTestPhysLocations(t) - CreateTestCacheGroups(t) - CreateTestServers(t) - CreateTestDeliveryServices(t) - CreateTestUsers(t) - - UpdateTestTenantsActive(t) - - ForceDeleteTestUsers(t) - DeleteTestDeliveryServices(t) - DeleteTestServers(t) - DeleteTestCacheGroups(t) - DeleteTestPhysLocations(t) - DeleteTestRegions(t) - DeleteTestDivisions(t) - DeleteTestStatuses(t) - DeleteTestProfiles(t) - DeleteTestParameters(t) - DeleteTestTenants(t) - DeleteTestTypes(t) - DeleteTestCDNs(t) -} - func ExtractXMLID(ds *tc.DeliveryServiceNullable) string { if ds.XMLID != nil { return *ds.XMLID diff --git a/traffic_ops/testing/api/v3/user_test.go b/traffic_ops/testing/api/v3/user_test.go index 643812dd99..38a8ff73e1 100644 --- a/traffic_ops/testing/api/v3/user_test.go +++ b/traffic_ops/testing/api/v3/user_test.go @@ -30,7 +30,7 @@ import ( ) func TestUsers(t *testing.T) { - WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, DeliveryServices, Users}, func() { + WithObjs(t, []TCObj{Tenants, Parameters, Users}, func() { UpdateTestUsers(t) RolenameCapitalizationTest(t) OpsUpdateAdminTest(t) diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go index c8db101212..5bbeefa472 100644 --- a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go +++ b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go @@ -184,6 +184,28 @@ func CreateV15(w http.ResponseWriter, r *http.Request) { api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Deliveryservice creation was successful.", []tc.DeliveryServiceNullableV15{*res}) } +func CreateV30(w http.ResponseWriter, r *http.Request) { + inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil) + if userErr != nil || sysErr != nil { + api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr) + return + } + defer inf.Close() + + ds := tc.DeliveryServiceNullableV30{} + if err := json.NewDecoder(r.Body).Decode(&ds); err != nil { + api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("decoding: "+err.Error()), nil) + return + } + + res, status, userErr, sysErr := createV30(w, r, inf, ds) + if userErr != nil || sysErr != nil { + api.HandleErr(w, r, inf.Tx.Tx, status, userErr, sysErr) + return + } + api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Deliveryservice creation was successful.", []tc.DeliveryServiceNullableV30{*res}) +} + func createV12(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS tc.DeliveryServiceNullableV12) (*tc.DeliveryServiceNullableV12, int, error, error) { dsV13 := tc.DeliveryServiceNullableV13{DeliveryServiceNullableV12: reqDS} res, status, userErr, sysErr := createV13(w, r, inf, dsV13) @@ -211,8 +233,17 @@ func createV14(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS t return nil, status, userErr, sysErr } -// create creates the given ds in the database, and returns the DS with its id and other fields created on insert set. On error, the HTTP status code, user error, and system error are returned. The status code SHOULD NOT be used, if both errors are nil. func createV15(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS tc.DeliveryServiceNullableV15) (*tc.DeliveryServiceNullableV15, int, error, error) { + dsV30 := tc.DeliveryServiceNullableV30{DeliveryServiceNullableV15: reqDS} + res, status, userErr, sysErr := createV30(w, r, inf, dsV30) + if res != nil { + return &res.DeliveryServiceNullableV15, status, userErr, sysErr + } + return nil, status, userErr, sysErr +} + +// create creates the given ds in the database, and returns the DS with its id and other fields created on insert set. On error, the HTTP status code, user error, and system error are returned. The status code SHOULD NOT be used, if both errors are nil. +func createV30(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS tc.DeliveryServiceNullableV30) (*tc.DeliveryServiceNullableV30, int, error, error) { ds := tc.DeliveryServiceNullable(reqDS) user := inf.User tx := inf.Tx.Tx @@ -283,6 +314,7 @@ func createV15(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS t &ds.SigningAlgorithm, &ds.SSLKeyVersion, &ds.TenantID, + &ds.Topology, &ds.TRRequestHeaders, &ds.TRResponseHeaders, &ds.TypeID, @@ -371,7 +403,7 @@ func createV15(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS t return nil, http.StatusInternalServerError, nil, errors.New("error writing to audit log: " + err.Error()) } - dsLatest := tc.DeliveryServiceNullableV15(ds) + dsLatest := tc.DeliveryServiceNullableV30(ds) return &dsLatest, http.StatusOK, nil, nil } @@ -426,8 +458,10 @@ func (ds *TODeliveryService) Read() ([]interface{}, error, error, int) { for _, ds := range dses { switch { // NOTE: it's required to handle minor version cases in a descending >= manner - case version.Major > 1 || version.Minor >= 5: + case version.Major > 2: returnable = append(returnable, ds) + case version.Major > 1 || version.Minor >= 5: + returnable = append(returnable, ds.DeliveryServiceNullableV15) case version.Minor >= 4: returnable = append(returnable, ds.DeliveryServiceNullableV14) case version.Minor >= 3: @@ -541,6 +575,31 @@ func UpdateV15(w http.ResponseWriter, r *http.Request) { api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Deliveryservice update was successful.", []tc.DeliveryServiceNullableV15{*res}) } +func UpdateV30(w http.ResponseWriter, r *http.Request) { + inf, userErr, sysErr, errCode := api.NewInfo(r, nil, []string{"id"}) + if userErr != nil || sysErr != nil { + api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr) + return + } + defer inf.Close() + + id := inf.IntParams["id"] + + ds := tc.DeliveryServiceNullableV30{} + if err := json.NewDecoder(r.Body).Decode(&ds); err != nil { + api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("malformed JSON: "+err.Error()), nil) + return + } + ds.ID = &id + + res, status, userErr, sysErr := updateV30(w, r, inf, &ds) + if userErr != nil || sysErr != nil { + api.HandleErr(w, r, inf.Tx.Tx, status, userErr, sysErr) + return + } + api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Deliveryservice update was successful.", []tc.DeliveryServiceNullableV30{*res}) +} + func updateV12(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS *tc.DeliveryServiceNullableV12) (*tc.DeliveryServiceNullableV12, int, error, error) { dsV13 := tc.DeliveryServiceNullableV13{DeliveryServiceNullableV12: *reqDS} // query the DB for existing 1.3 fields in order to "upgrade" this 1.2 request into a 1.3 request @@ -637,6 +696,31 @@ WHERE } func updateV15(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS *tc.DeliveryServiceNullableV15) (*tc.DeliveryServiceNullableV15, int, error, error) { + dsV30 := tc.DeliveryServiceNullableV30{DeliveryServiceNullableV15: *reqDS} + // query the DB for existing 3.0 fields in order to "upgrade" this 1.5 request into a 3.0 request + query := ` +SELECT + ds.topology +FROM + deliveryservice ds +WHERE + ds.id = $1` + if err := inf.Tx.Tx.QueryRow(query, *reqDS.ID).Scan( + &dsV30.Topology, + ); err != nil { + if err == sql.ErrNoRows { + return nil, http.StatusNotFound, fmt.Errorf("delivery service ID %d not found", *dsV30.ID), nil + } + return nil, http.StatusInternalServerError, nil, fmt.Errorf("querying delivery service ID %d: %s", *dsV30.ID, err.Error()) + } + res, status, userErr, sysErr := updateV30(w, r, inf, &dsV30) + if res != nil { + return &res.DeliveryServiceNullableV15, status, userErr, sysErr + } + return nil, status, userErr, sysErr +} + +func updateV30(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS *tc.DeliveryServiceNullableV30) (*tc.DeliveryServiceNullableV30, int, error, error) { converted := tc.DeliveryServiceNullable(*reqDS) ds := &converted tx := inf.Tx.Tx @@ -738,6 +822,7 @@ func updateV15(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS * &ds.MaxOriginConnections, &ds.EcsEnabled, &ds.RangeSliceBlockSize, + &ds.Topology, &ds.ID) if err != nil { @@ -836,7 +921,7 @@ func updateV15(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS * if err := api.CreateChangeLogRawErr(api.ApiChange, "Updated ds: "+*ds.XMLID+" id: "+strconv.Itoa(*ds.ID), user, tx); err != nil { return nil, http.StatusInternalServerError, nil, errors.New("writing change log entry: " + err.Error()) } - dsLatest := tc.DeliveryServiceNullableV15(*ds) + dsLatest := tc.DeliveryServiceNullableV30(*ds) return &dsLatest, http.StatusOK, nil, nil } @@ -897,15 +982,16 @@ func readGetDeliveryServices(params map[string]string, tx *sqlx.Tx, user *auth.C // Query Parameters to Database Query column mappings // see the fields mapped in the SQL query queryParamsToSQLCols := map[string]dbhelpers.WhereColumnInfo{ - "id": dbhelpers.WhereColumnInfo{"ds.id", api.IsInt}, - "cdn": dbhelpers.WhereColumnInfo{"ds.cdn_id", api.IsInt}, - "xml_id": dbhelpers.WhereColumnInfo{"ds.xml_id", nil}, - "xmlId": dbhelpers.WhereColumnInfo{"ds.xml_id", nil}, - "profile": dbhelpers.WhereColumnInfo{"ds.profile", api.IsInt}, - "type": dbhelpers.WhereColumnInfo{"ds.type", api.IsInt}, - "logsEnabled": dbhelpers.WhereColumnInfo{"ds.logs_enabled", api.IsBool}, - "tenant": dbhelpers.WhereColumnInfo{"ds.tenant_id", api.IsInt}, - "signingAlgorithm": dbhelpers.WhereColumnInfo{"ds.signing_algorithm", nil}, + "id": {"ds.id", api.IsInt}, + "cdn": {"ds.cdn_id", api.IsInt}, + "xml_id": {"ds.xml_id", nil}, + "xmlId": {"ds.xml_id", nil}, + "profile": {"ds.profile", api.IsInt}, + "type": {"ds.type", api.IsInt}, + "logsEnabled": {"ds.logs_enabled", api.IsBool}, + "tenant": {"ds.tenant_id", api.IsInt}, + "signingAlgorithm": {"ds.signing_algorithm", nil}, + "topology": {"ds.topology", nil}, } where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(params, queryParamsToSQLCols) @@ -1135,6 +1221,7 @@ func GetDeliveryServices(query string, queryValues map[string]interface{}, tx *s &ds.SSLKeyVersion, &ds.TenantID, &ds.Tenant, + &ds.Topology, &ds.TRRequestHeaders, &ds.TRResponseHeaders, &ds.Type, @@ -1655,6 +1742,7 @@ ds.range_slice_block_size, ds.ssl_key_version, ds.tenant_id, tenant.name, +ds.topology, ds.tr_request_headers, ds.tr_response_headers, type.name, @@ -1726,8 +1814,9 @@ anonymous_blocking_enabled=$50, consistent_hash_regex=$51, max_origin_connections=$52, ecs_enabled=$53, -range_slice_block_size=$54 -WHERE id=$55 +range_slice_block_size=$54, +topology=$55 +WHERE id=$56 RETURNING last_updated ` } @@ -1783,6 +1872,7 @@ routing_name, signing_algorithm, ssl_key_version, tenant_id, +topology, tr_request_headers, tr_response_headers, type, @@ -1790,7 +1880,7 @@ xml_id, ecs_enabled, range_slice_block_size ) -VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52,$53,$54) +VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52,$53,$54,$55) RETURNING id, last_updated ` } diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests_test.go b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests_test.go index b4302a5ad2..f932f5a1d8 100644 --- a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests_test.go +++ b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests_test.go @@ -58,26 +58,18 @@ func TestGetDeliveryServiceRequest(t *testing.T) { b := true u := "UPDATE" st := tc.RequestStatusSubmitted + ds := tc.DeliveryServiceNullable{} + ds.XMLID = &s + ds.CDNID = &i + ds.LogsEnabled = &b + ds.DSCP = nil + ds.GeoLimit = &i + ds.Active = &b + ds.TypeID = &i r := &TODeliveryServiceRequest{DeliveryServiceRequestNullable: tc.DeliveryServiceRequestNullable{ - ChangeType: &u, - Status: &st, - DeliveryService: &tc.DeliveryServiceNullable{ - DeliveryServiceNullableV14: tc.DeliveryServiceNullableV14{ - DeliveryServiceNullableV13: tc.DeliveryServiceNullableV13{ - DeliveryServiceNullableV12: tc.DeliveryServiceNullableV12{ - DeliveryServiceNullableV11: tc.DeliveryServiceNullableV11{ - XMLID: &s, - CDNID: &i, - LogsEnabled: &b, - DSCP: nil, - GeoLimit: &i, - Active: &b, - TypeID: &i, - }, - }, - }, - }, - }, + ChangeType: &u, + Status: &st, + DeliveryService: &ds, }} expectedErrors := []string{ diff --git a/traffic_ops/traffic_ops_golang/routing/routes.go b/traffic_ops/traffic_ops_golang/routing/routes.go index 5bfd8ae828..e676d219b5 100644 --- a/traffic_ops/traffic_ops_golang/routing/routes.go +++ b/traffic_ops/traffic_ops_golang/routing/routes.go @@ -472,8 +472,8 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) { ////DeliveryServices {api.Version{3, 0}, http.MethodGet, `deliveryservices/?$`, api.ReadHandler(&deliveryservice.TODeliveryService{}), auth.PrivLevelReadOnly, Authenticated, nil, 22383172943, noPerlBypass}, - {api.Version{3, 0}, http.MethodPost, `deliveryservices/?$`, deliveryservice.CreateV15, auth.PrivLevelOperations, Authenticated, nil, 2064314323, noPerlBypass}, - {api.Version{3, 0}, http.MethodPut, `deliveryservices/{id}/?$`, deliveryservice.UpdateV15, auth.PrivLevelOperations, Authenticated, nil, 27665675273, noPerlBypass}, + {api.Version{3, 0}, http.MethodPost, `deliveryservices/?$`, deliveryservice.CreateV30, auth.PrivLevelOperations, Authenticated, nil, 2064314323, noPerlBypass}, + {api.Version{3, 0}, http.MethodPut, `deliveryservices/{id}/?$`, deliveryservice.UpdateV30, auth.PrivLevelOperations, Authenticated, nil, 27665675273, noPerlBypass}, {api.Version{3, 0}, http.MethodPut, `deliveryservices/{id}/safe/?$`, deliveryservice.UpdateSafe, auth.PrivLevelOperations, Authenticated, nil, 2472109313, perlBypass}, {api.Version{3, 0}, http.MethodDelete, `deliveryservices/{id}/?$`, api.DeleteHandler(&deliveryservice.TODeliveryService{}), auth.PrivLevelOperations, Authenticated, nil, 2226420743, noPerlBypass}, {api.Version{3, 0}, http.MethodGet, `deliveryservices/{id}/servers/eligible/?$`, deliveryservice.GetServersEligible, auth.PrivLevelReadOnly, Authenticated, nil, 2747615843, noPerlBypass}, diff --git a/traffic_portal/app/src/common/api/ServerService.js b/traffic_portal/app/src/common/api/ServerService.js index ce689dd124..afc7b7ecff 100644 --- a/traffic_portal/app/src/common/api/ServerService.js +++ b/traffic_portal/app/src/common/api/ServerService.js @@ -139,14 +139,6 @@ var ServerService = function($http, locationUtils, messageModel, ENV) { ); }; - this.getDeliveryServiceServers = function(dsId) { - return $http.get(ENV.api['root'] + 'deliveryservices/' + dsId + '/servers').then( - function (result) { - return result.data.response; - } - ); - }; - this.getEligibleDeliveryServiceServers = function(dsId) { return $http.get(ENV.api['root'] + 'deliveryservices/' + dsId + '/servers/eligible').then( function (result) { diff --git a/traffic_portal/app/src/common/modules/form/deliveryService/FormDeliveryServiceController.js b/traffic_portal/app/src/common/modules/form/deliveryService/FormDeliveryServiceController.js index 66209da419..bbb8deee14 100644 --- a/traffic_portal/app/src/common/modules/form/deliveryService/FormDeliveryServiceController.js +++ b/traffic_portal/app/src/common/modules/form/deliveryService/FormDeliveryServiceController.js @@ -17,7 +17,7 @@ * under the License. */ -var FormDeliveryServiceController = function(deliveryService, dsCurrent, origin, type, types, $scope, $location, $uibModal, $window, formUtils, locationUtils, tenantUtils, deliveryServiceUtils, cdnService, profileService, tenantService, propertiesModel, userModel) { +var FormDeliveryServiceController = function(deliveryService, dsCurrent, origin, topologies, type, types, $scope, $location, $uibModal, $window, formUtils, locationUtils, tenantUtils, deliveryServiceUtils, cdnService, profileService, tenantService, propertiesModel, userModel) { var getCDNs = function() { cdnService.getCDNs() @@ -58,6 +58,8 @@ var FormDeliveryServiceController = function(deliveryService, dsCurrent, origin, $scope.origin = origin[0]; + $scope.topologies = topologies; + $scope.showChartsButton = propertiesModel.properties.deliveryServices.charts.customLink.show; $scope.openCharts = deliveryServiceUtils.openCharts; @@ -312,5 +314,5 @@ var FormDeliveryServiceController = function(deliveryService, dsCurrent, origin, }; -FormDeliveryServiceController.$inject = ['deliveryService', 'dsCurrent', 'origin', 'type', 'types', '$scope', '$location', '$uibModal', '$window', 'formUtils', 'locationUtils', 'tenantUtils', 'deliveryServiceUtils', 'cdnService', 'profileService', 'tenantService', 'propertiesModel', 'userModel']; +FormDeliveryServiceController.$inject = ['deliveryService', 'dsCurrent', 'origin', 'topologies', 'type', 'types', '$scope', '$location', '$uibModal', '$window', 'formUtils', 'locationUtils', 'tenantUtils', 'deliveryServiceUtils', 'cdnService', 'profileService', 'tenantService', 'propertiesModel', 'userModel']; module.exports = FormDeliveryServiceController; diff --git a/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js b/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js index 40bf5600d9..2c03d25baf 100644 --- a/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js +++ b/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js @@ -17,10 +17,10 @@ * under the License. */ -var FormEditDeliveryServiceController = function(deliveryService, origin, type, types, $scope, $state, $controller, $uibModal, $anchorScroll, locationUtils, deliveryServiceService, deliveryServiceRequestService, messageModel, propertiesModel, userModel) { +var FormEditDeliveryServiceController = function(deliveryService, origin, topologies, type, types, $scope, $state, $controller, $uibModal, $anchorScroll, locationUtils, deliveryServiceService, deliveryServiceRequestService, messageModel, propertiesModel, userModel) { // extends the FormDeliveryServiceController to inherit common methods - angular.extend(this, $controller('FormDeliveryServiceController', { deliveryService: deliveryService, dsCurrent: deliveryService, origin: origin, type: type, types: types, $scope: $scope })); + angular.extend(this, $controller('FormDeliveryServiceController', { deliveryService: deliveryService, dsCurrent: deliveryService, origin: origin, topologies: topologies, type: type, types: types, $scope: $scope })); var createDeliveryServiceDeleteRequest = function(deliveryService) { var params = { @@ -273,5 +273,5 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, }; -FormEditDeliveryServiceController.$inject = ['deliveryService', 'origin', 'type', 'types', '$scope', '$state', '$controller', '$uibModal', '$anchorScroll', 'locationUtils', 'deliveryServiceService', 'deliveryServiceRequestService', 'messageModel', 'propertiesModel', 'userModel']; +FormEditDeliveryServiceController.$inject = ['deliveryService', 'origin', 'topologies', 'type', 'types', '$scope', '$state', '$controller', '$uibModal', '$anchorScroll', 'locationUtils', 'deliveryServiceService', 'deliveryServiceRequestService', 'messageModel', 'propertiesModel', 'userModel']; module.exports = FormEditDeliveryServiceController; diff --git a/traffic_portal/app/src/common/modules/form/deliveryService/form.deliveryService.DNS.tpl.html b/traffic_portal/app/src/common/modules/form/deliveryService/form.deliveryService.DNS.tpl.html index d6d18a747f..6d1e4ad050 100644 --- a/traffic_portal/app/src/common/modules/form/deliveryService/form.deliveryService.DNS.tpl.html +++ b/traffic_portal/app/src/common/modules/form/deliveryService/form.deliveryService.DNS.tpl.html @@ -59,7 +59,7 @@