Skip to content

Commit

Permalink
feat(dedicated): add vrack orderable in ipv4 (#12779)
Browse files Browse the repository at this point in the history
ref: MANAGER-14886

Signed-off-by: Sachin Ramesh <[email protected]>
  • Loading branch information
sachinrameshn authored Oct 31, 2024
1 parent 19efae8 commit ccaece3
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class IpAgoraOrder {
planCode,
productId = 'ip',
pricingMode = 'default',
productRegionName,
quantity = 1,
serviceName,
datacenter,
Expand Down Expand Up @@ -76,6 +77,14 @@ export default class IpAgoraOrder {
});
}

if (productRegionName) {
const [region] = productRegionName?.split('-') || [];
productToOrder.configuration.push({
label: 'region',
value: region?.trim()?.toLowerCase(),
});
}

if (destination) {
productToOrder.configuration.push({
label: 'destination',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const PRODUCT_TYPES = {
apiTypeName: 'parking',
typeName: 'parking',
},
vrack: {
apiTypeName: 'VRACK',
typeName: 'VRACK',
},
};

export const IP_AGORA = {
Expand Down Expand Up @@ -123,6 +127,25 @@ export const IP_LOCATION_GROUPS_BASED_ON_DATACENTER = [
{ labels: ['USA'], countries: ['us'], datacenter: ['HIL', 'VIN'] },
];

/* To be replaced once we have region list coming from API for the Vrack, as of now consider IPV6 regions */
export const REGION_TO_DATACENTER = {
'eu-west-rbx': 'RBX',
'eu-west-gra': 'GRA',
'eu-west-sbg': 'SBG',
'eu-west-par': 'PAR',
'labeu-west-1-preprod': 'CR2',
'eu-west-lim': 'LIM',
'eu-central-waw': 'WAW',
'eu-west-eri': 'ERI',
'ca-east-bhs': 'BHS',
'ca-east-tor': 'YYZ',
'ap-southeast-sgp': 'SGP',
'ap-southeast-syd': 'SYD',
'ap-south-mum': 'YNM',
'us-east-vin': 'VIN',
'us-west-hil': 'HIL',
};

export default {
FETCH_PRICE_MAX_TRIES,
IP_LOCATION_GROUPS,
Expand All @@ -137,4 +160,5 @@ export default {
DATACENTER_TO_COUNTRY,
DATACENTER_TO_REGION,
IP_LOCATION_GROUPS_BASED_ON_DATACENTER,
REGION_TO_DATACENTER,
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DATACENTER_TO_COUNTRY,
DATACENTER_TO_REGION,
IP_LOCATION_GROUPS_BASED_ON_DATACENTER,
REGION_TO_DATACENTER,
} from './ipv4.constant';

export default class AgoraIpV4OrderController {
Expand Down Expand Up @@ -72,8 +73,8 @@ export default class AgoraIpV4OrderController {

$onInit() {
this.catalogByLocation = [];
this.isParkingIp = false;
this.parkingIpOffers = [];
this.isParkingIpOrVrack = false;
this.IpOffers = [];
this.model = {
params: {},
selectedService: null,
Expand Down Expand Up @@ -116,6 +117,7 @@ export default class AgoraIpV4OrderController {
.all({
user: this.User.getUser(),
services: this.Ipv4AgoraOrder.getServices(),
vrack: this.Ipv4AgoraOrder.getVracks(), // toDo
})
.then((results) => {
results.services.push({
Expand All @@ -124,7 +126,8 @@ export default class AgoraIpV4OrderController {
type: 'parking',
});
this.user = results.user;
this.services = results.services.map((service) => ({
this.services = [...results.services, ...results.vrack];
this.services = this.services.map((service) => ({
...service,
translatedType:
service.type === 'parking'
Expand Down Expand Up @@ -311,21 +314,65 @@ export default class AgoraIpV4OrderController {
this.trackStep(3);
}

/* To be replaced once we have region list coming from API for the Vrack, as of now consider IPV6 regions */
getIpv6RegionsWithPlan(IpOffers) {
this.IP_REGION = 'ip_region';
return IpOffers.map((plan) => {
const {
details: {
product: { configurations },
},
} = plan;
const regionConfig = configurations.find(
(config) => config.name === this.IP_REGION,
);

return regionConfig.values.map((regionId) => ({
regionId,
plan: plan.planCode,
}));
}).flat();
}

static getMacroRegion(region) {
const localZonePattern = /^lz/i;
const devZonePattern = /^1-/i;

let macro;
const local = region
.split('-')
?.slice(2)
?.join('-');

if (devZonePattern.test(local)) {
macro = [local];
} else {
const nbOfSlice = localZonePattern.test(local) ? 3 : 2;
macro = /[\D]{2,3}/.exec(
region
.split('-')
?.slice(nbOfSlice)
?.join('-'),
);
}

return (macro && macro[0]) || '';
}

onIpServiceSelection() {
this.isParkingIp =
this.model?.selectedService?.type === PRODUCT_TYPES.parking.typeName;
if (this.isParkingIp) {
this.isParkingIpOrVrack =
this.model?.selectedService?.type === PRODUCT_TYPES.parking.typeName ||
this.model?.selectedService?.type === PRODUCT_TYPES.vrack.typeName;
this.IpOffers = this.ipCatalog.filter((plan) =>
/^ip-v4|^ip-failover/.test(plan.planCode),
);
if (this.model?.selectedService?.type === PRODUCT_TYPES.parking.typeName) {
this.loading.region = true;
this.parkingIpOffers = this.ipCatalog.filter((plan) =>
/^ip-v4|^ip-failover/.test(plan.planCode),
);
const DATACENTERS = this.parkingIpOffers
.map((ipOffer) => {
return ipOffer.details.product.configurations.find(
(config) => config.name === 'datacenter',
)?.values;
})
.flat();
const DATACENTERS = this.IpOffers.map((ipOffer) => {
return ipOffer.details.product.configurations.find(
(config) => config.name === 'datacenter',
)?.values;
}).flat();
const uniqueDatacenters = [...new Set(DATACENTERS)];
this.catalogByLocation = uniqueDatacenters.map((datacenter) => {
const flag =
Expand All @@ -342,6 +389,30 @@ export default class AgoraIpV4OrderController {
this.loading.region = false;
return null;
}

if (this.model?.selectedService?.type === PRODUCT_TYPES.vrack.typeName) {
this.loading.region = true;
this.Ipv6Offers = this.ipCatalog.filter(
(plan) => plan.planCode.match(/^ip-v6.*/) != null,
);
/* To be replaced once we have region list coming from API for the Vrack, as of now consider IPV6 regions */
this.ipv6RegionsWithPlan = this.getIpv6RegionsWithPlan(this.Ipv6Offers);
this.catalogByLocation = this.ipv6RegionsWithPlan.map(({ regionId }) => {
const datacenter = REGION_TO_DATACENTER[regionId];
const flag =
datacenter === 'ERI' ? 'gb' : DATACENTER_TO_COUNTRY[datacenter];
return {
datacenter,
regionName: regionId,
location: this.$translate.instant(
`ip_agora_ipv6_location_${regionId}`,
),
icon: `oui-flag oui-flag_${flag}`,
};
});
this.loading.region = false;
return null;
}
return this.manageLoadIpOffers();
}

Expand Down Expand Up @@ -406,22 +477,21 @@ export default class AgoraIpV4OrderController {
ipOffersPromise = this.loadPrivateCloudIpOffers(
get(this.model, 'selectedService.serviceName'),
);
} else if (this.isParkingIp) {
} else if (this.isParkingIpOrVrack) {
// Country for Single IP selection in parking
const country = [
DATACENTER_TO_COUNTRY[this.model.selectedRegion.datacenter],
];
// Multiple countries are available for block IP selection in parking and vrack
const countries = AgoraIpV4OrderController.getCountriesFromDatacenter(
this.model.selectedRegion.datacenter,
this.parkingIpOffers,
this.IpOffers,
).map((value) => value.toLowerCase());
const ipOfferDetails = this.parkingIpOffers.map(
this.createOfferDto.bind(this),
);
const ipOfferDetails = this.IpOffers.map(this.createOfferDto.bind(this));
const ipOffersByDatacenter = AgoraIpV4OrderController.getRegionFromDatacenter(
this.model.selectedRegion.datacenter,
);

blockIpOfferDetails = this.filterOffer(
ipOfferDetails,
'productShortName',
Expand Down Expand Up @@ -555,7 +625,7 @@ export default class AgoraIpV4OrderController {
this.model.params.selectedCountry = head(
get(this.model, 'params.selectedOffer.countries'),
);
} else if (this.isParkingIp) {
} else if (this.isParkingIpOrVrack) {
const code = DATACENTER_TO_COUNTRY[this.model.selectedRegion.datacenter];
this.model.params.selectedCountry = {
code: code.toUpperCase(),
Expand Down Expand Up @@ -614,17 +684,26 @@ export default class AgoraIpV4OrderController {
serviceName: get(this.model, 'selectedService.serviceName'),
...commonProductProps,
});
} else if (this.isParkingIp) {
} else if (
this.model?.selectedService?.type === PRODUCT_TYPES.parking.typeName
) {
const { datacenter } = this.model.selectedRegion;
productToOrder = this.IpAgoraOrder.constructor.createProductToOrder({
organisation: get(
this.model.params,
'selectedOrganisation.organisationId',
),
organisation: this.model.params.selectedOrganisation.organisationId,
...commonProductProps,
country: params.selectedCountry?.code,
datacenter,
});
} else if (
this.model?.selectedService?.type === PRODUCT_TYPES.vrack.typeName
) {
const { datacenter } = this.model.selectedRegion;
productToOrder = this.IpAgoraOrder.constructor.createProductToOrder({
organisation: this.model.params.selectedOrganisation.organisationId,
...commonProductProps,
productRegionName: this.model.params.selectedOffer.productRegion,
datacenter,
});
} else {
productToOrder = this.IpAgoraOrder.constructor.createProductToOrder({
organisation: get(
Expand Down Expand Up @@ -697,7 +776,8 @@ export default class AgoraIpV4OrderController {
PRODUCT_TYPES.privateCloud.typeName ||
this.model.selectedService?.type ===
PRODUCT_TYPES.dedicatedServer.typeName ||
this.model.selectedService?.type === PRODUCT_TYPES.parking.typeName
this.model.selectedService?.type === PRODUCT_TYPES.parking.typeName ||
this.model.selectedService?.type === PRODUCT_TYPES.vrack.typeName
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@
></div>
</oui-step-form>

<!-- Select the region for Parking IP-->
<!-- Select the region for Parking IP / Vrack-->

<oui-step-form
data-position="1"
data-ng-if="$ctrl.isParkingIp"
data-ng-if="$ctrl.isParkingIpOrVrack"
data-id="region"
data-name="region_selection"
data-header="{{:: ('ip_agora_table_header_region' | translate)}}"
Expand Down Expand Up @@ -92,7 +93,7 @@

<!-- Choice your solution -->
<oui-step-form
data-position="{{$ctrl.isParkingIp ? 2: 1}}"
data-position="{{$ctrl.isParkingIpOrVrack ? 2: 1}}"
data-id="offer"
data-name="offer_selection"
data-header="{{:: 'ip_agora_table_header_offer' | translate }}"
Expand Down Expand Up @@ -226,7 +227,7 @@ <h4 class="text-center">

<!-- Select the IP geolocation -->
<oui-step-form
data-position="{{$ctrl.isParkingIp ? 3: 2}}"
data-position="{{$ctrl.isParkingIpOrVrack ? 3: 2}}"
data-id="country"
data-name="country_selection"
data-header="{{:: 'ip_agora_ipv4_localisation_title' | translate }}"
Expand Down Expand Up @@ -273,7 +274,7 @@ <h4 class="text-center">

<!-- Select the organisation -->
<oui-step-form
data-position="{{$ctrl.isParkingIp ? 4: 3}}"
data-position="{{$ctrl.isParkingIpOrVrack ? 4: 3}}"
data-ng-if="$ctrl.model.params.selectedOffer.isIpBlockOffer && !$ctrl.isPrivateCloudOffer"
data-id="organisation"
data-name="organisation_selection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { FETCH_PRICE_MAX_TRIES, PRODUCT_TYPES } from './ipv4.constant';

export default class Ipv4AgoraOrder {
/* @ngInject */
constructor($q, $http, OvhHttp, IpAgoraOrder) {
constructor($q, $http, OvhHttp, IpAgoraOrder, iceberg) {
this.$q = $q;
this.$http = $http;
this.OvhHttp = OvhHttp;
this.IpAgoraOrder = IpAgoraOrder;
this.iceberg = iceberg;
this.fetchPricesTries = 0;
}

Expand All @@ -21,6 +22,24 @@ export default class Ipv4AgoraOrder {
});
}

getVracks() {
return this.iceberg('/vrack')
.query()
.expand('CachedObjectList-Pages')
.execute()
.$promise.then(({ data }) =>
data.map((vrack) => {
const serviceName = vrack.iam.urn.split(':').pop();
const displayName = vrack.name || serviceName;
return {
displayName,
serviceName,
type: PRODUCT_TYPES.vrack.apiTypeName,
};
}),
);
}

getServices() {
return this.$q
.all([
Expand Down

0 comments on commit ccaece3

Please sign in to comment.