Skip to content

Commit

Permalink
feat(dedicated.ip): allow parking ip as destination (#12509)
Browse files Browse the repository at this point in the history
ref: MANAGER-14569

Signed-off-by: Sachin Ramesh <[email protected]>
Co-Authored-by: CDS Translator Agent <[email protected]>
  • Loading branch information
2 people authored and vovh committed Oct 14, 2024
1 parent d1a07ff commit b713a6e
Show file tree
Hide file tree
Showing 21 changed files with 395 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class AgoraIpOrderCtrl {
}

getlowestPrice() {
const plans = this.ipCatalog.filter((plan) =>
const plans = this.ipCatalog?.filter((plan) =>
Object.values(IP_FAILOVER_PLANCODE).includes(plan.planCode),
);
plans.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class IpAgoraOrder {
pricingMode = 'default',
quantity = 1,
serviceName,
datacenter,
}) {
const productToOrder = {
configuration,
Expand All @@ -51,6 +52,7 @@ export default class IpAgoraOrder {
productId,
quantity,
serviceName,
datacenter,
};

if (description) {
Expand Down Expand Up @@ -95,6 +97,13 @@ export default class IpAgoraOrder {
});
}

if (datacenter) {
productToOrder.configuration.push({
label: 'datacenter',
value: datacenter,
});
}

return productToOrder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const PRODUCT_TYPES = {
apiTypeName: 'VPS',
typeName: 'VPS',
},
parking: {
apiTypeName: 'parking',
typeName: 'parking',
},
};

export const IP_AGORA = {
Expand Down Expand Up @@ -67,6 +71,56 @@ export const BLOCK_ADDITIONAL_IP = 'Block Additional IP';

export { TRACKING_PREFIX, ADDITIONAL_IP, ALERT_ID, IP_FAILOVER_PLANCODE };

export const DATACENTER_TO_COUNTRY = {
PAR: 'fr',
GRA: 'fr',
SBG: 'fr',
LIM: 'de',
WAW: 'pl',
ERI: 'uk',
VIN: 'us',
HIL: 'us',
BHS: 'ca',
SGP: 'sg',
SYD: 'au',
RBX: 'fr',
YYZ: 'ca',
YNM: 'in',
CR2: 'fr',
};

export const DATACENTER_TO_REGION = {
RBX: 'eu-west-rbx',
GRA: 'eu-west-gra',
SBG: 'eu-west-sbg',
PAR: 'eu-west-par',
CR2: 'labeu-west-1-preprod',
LIM: 'eu-west-lim',
WAW: 'eu-central-waw',
ERI: 'eu-west-eri',
BHS: 'ca-east-bhs',
YYZ: 'ca-east-tor',
SGP: 'ap-southeast-sgp',
SYD: 'ap-southeast-syd',
YNM: 'ap-south-mum',
VIN: 'us-east-vin',
HIL: 'us-west-hil',
};

export const IP_LOCATION_GROUPS_BASED_ON_DATACENTER = [
{
labels: ['APAC/CANADA', 'CANADA - ASIA'],
countries: ['au', 'ca', 'sg', 'in'],
datacenter: ['SYD', 'BHS', 'YYZ', 'YNM', 'SGP'],
},
{
labels: ['EUROPE'],
countries: ['de', 'fr', 'pl', 'uk'],
datacenter: ['RBX', 'GRA', 'LIM', 'CR2', 'PAR', 'SBG', 'WAW', 'ERI'],
},
{ labels: ['USA'], countries: ['us'], datacenter: ['HIL', 'VIN'] },
];

export default {
FETCH_PRICE_MAX_TRIES,
IP_LOCATION_GROUPS,
Expand All @@ -77,4 +131,7 @@ export default {
IP_FAILOVER_PLANCODE,
BLOCK_ADDITIONAL_IP,
ALERT_ID,
DATACENTER_TO_COUNTRY,
DATACENTER_TO_REGION,
IP_LOCATION_GROUPS_BASED_ON_DATACENTER,
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
BLOCK_ADDITIONAL_IP,
IP_FAILOVER_PLANCODE,
ALERT_ID,
DATACENTER_TO_COUNTRY,
DATACENTER_TO_REGION,
IP_LOCATION_GROUPS_BASED_ON_DATACENTER,
} from './ipv4.constant';

export default class AgoraIpV4OrderController {
Expand Down Expand Up @@ -67,6 +70,9 @@ export default class AgoraIpV4OrderController {
}

$onInit() {
this.catalogByLocation = [];
this.isParkingIp = false;
this.parkingIpOffers = [];
this.model = {
params: {},
selectedService: null,
Expand Down Expand Up @@ -111,6 +117,11 @@ export default class AgoraIpV4OrderController {
services: this.Ipv4AgoraOrder.getServices(),
})
.then((results) => {
results.services.push({
displayName: this.$translate.instant('ip_servicetype__PARK'),
serviceName: 'parking',
type: 'parking',
});
this.user = results.user;
this.services = results.services.map((service) => ({
...service,
Expand Down Expand Up @@ -152,6 +163,10 @@ export default class AgoraIpV4OrderController {
(config) => config.name === 'country',
).values;

const datacenterCodes = ipOffer.details.product.configurations.find(
(config) => config.name === 'datacenter',
)?.values;

return {
productName: ipOffer.invoiceName,
productShortName: ipOffer.invoiceName.replace(/^.*\]\s*/, ''),
Expand All @@ -162,6 +177,7 @@ export default class AgoraIpV4OrderController {
).price,
maximumQuantity,
quantities: range(1, maximumQuantity + 1),
datacenterCodes,
countries: countryCodes.map((countryCode) => ({
code: countryCode,
description: this.$translate.instant(
Expand Down Expand Up @@ -206,13 +222,15 @@ export default class AgoraIpV4OrderController {
}

request.then((region) => {
this.model.selectedServiceRegion =
this.model.selectedService?.type ===
PRODUCT_TYPES.dedicatedServer.typeName
? this.$translate.instant(`ip_region_${region}`)
: this.ovhManagerRegionService.getTranslatedMicroRegionLocation(
region.toUpperCase(),
);
if (region) {
this.model.selectedServiceRegion =
this.model.selectedService?.type ===
PRODUCT_TYPES.dedicatedServer.typeName
? this.$translate.instant(`ip_region_${region}`)
: this.ovhManagerRegionService.getTranslatedMicroRegionLocation(
region.toUpperCase(),
);
}
this.loadServiceRegion = false;
});
}
Expand All @@ -237,6 +255,23 @@ export default class AgoraIpV4OrderController {
return 'USA';
}

static getRegionFromDatacenter(datacenter) {
return IP_LOCATION_GROUPS_BASED_ON_DATACENTER.find((group) =>
group.datacenter.includes(datacenter),
)?.labels;
}

static getCountriesFromDatacenter(selectedServiceDatacenter, ipOffers) {
const ipOffer = ipOffers.find((offer) => {
return offer.details.product.configurations
.find((config) => config.name === 'datacenter')
?.values?.includes(selectedServiceDatacenter);
});
return ipOffer.details.product.configurations.find(
(config) => config.name === 'country',
)?.values;
}

loadPrivateCloudIpOffers(serviceName) {
const countries = this.orderableIpCountries.map((code) => {
return {
Expand Down Expand Up @@ -272,6 +307,40 @@ export default class AgoraIpV4OrderController {
this.trackStep(3);
}

onIpServiceSelection() {
this.isParkingIp =
this.model?.selectedService?.type === PRODUCT_TYPES.parking.typeName;
if (this.isParkingIp) {
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 uniqueDatacenters = [...new Set(DATACENTERS)];
this.catalogByLocation = uniqueDatacenters.map((datacenter) => {
const flag =
datacenter === 'ERI' ? 'gb' : DATACENTER_TO_COUNTRY[datacenter];
return {
datacenter,
regionName: DATACENTER_TO_REGION[datacenter],
location: this.$translate.instant(
`ip_agora_ipv6_location_${DATACENTER_TO_REGION[datacenter]}`,
),
icon: `oui-flag oui-flag_${flag}`,
};
});
this.loading.region = false;
return null;
}
return this.manageLoadIpOffers();
}

manageLoadIpOffers() {
this.trackStep(2);
this.loading.ipOffers = true;
Expand Down Expand Up @@ -323,23 +392,60 @@ export default class AgoraIpV4OrderController {
loadIpOffers() {
this.model.params = {};
let ipOffersPromise;
let failoverIpOfferDetails;
let blockIpOfferDetails;

this.isPrivateCloudOffer =
get(this.model, 'selectedService.type') ===
PRODUCT_TYPES.privateCloud.typeName;
this.model?.selectedService?.type === PRODUCT_TYPES.privateCloud.typeName;

if (this.isPrivateCloudOffer) {
ipOffersPromise = this.loadPrivateCloudIpOffers(
get(this.model, 'selectedService.serviceName'),
);
} else if (this.isParkingIp) {
// 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,
).map((value) => value.toLowerCase());
const ipOfferDetails = this.parkingIpOffers.map(
this.createOfferDto.bind(this),
);
const ipOffersByDatacenter = AgoraIpV4OrderController.getRegionFromDatacenter(
this.model.selectedRegion.datacenter,
);
blockIpOfferDetails = this.filterOffer(
ipOfferDetails,
'productShortName',
'block',
);
failoverIpOfferDetails = this.filterOffer(
ipOfferDetails,
'planCode',
'failover',
);
this.failoverIpOffers = this.getOfferDetails(
failoverIpOfferDetails,
ipOffersByDatacenter,
country,
);
this.blockIpOffers = this.getOfferDetails(
blockIpOfferDetails,
ipOffersByDatacenter,
countries,
).sort((a, b) => a.price.value - b.price.value);
} else {
ipOffersPromise = this.Ipv4AgoraOrder.getIpOffers(
this.user.ovhSubsidiary,
this.catalogName,
).then((ipOffers) => {
const ipOfferDetails = ipOffers.map(this.createOfferDto.bind(this));
let failoverIpOfferDetails;
let blockIpOfferDetails;
const ipOfferDetails = ipOffers
.filter((plan) => /^ip-v4|^ip-failover/.test(plan.planCode))
.map(this.createOfferDto.bind(this));
if (this.model.selectedService.type === PRODUCT_TYPES.vps.typeName) {
failoverIpOfferDetails = ipOfferDetails
.filter(({ planCode }) => planCode.includes('failover'))
Expand Down Expand Up @@ -445,6 +551,13 @@ export default class AgoraIpV4OrderController {
this.model.params.selectedCountry = head(
get(this.model, 'params.selectedOffer.countries'),
);
} else if (this.isParkingIp) {
const code = DATACENTER_TO_COUNTRY[this.model.selectedRegion.datacenter];
this.model.params.selectedCountry = {
code: code.toUpperCase(),
description: this.$translate.instant(`country_${code.toUpperCase()}`),
icon: `oui-flag oui-flag_${code}`,
};
}
}

Expand Down Expand Up @@ -497,6 +610,17 @@ export default class AgoraIpV4OrderController {
serviceName: get(this.model, 'selectedService.serviceName'),
...commonProductProps,
});
} else if (this.isParkingIp) {
const { datacenter } = this.model.selectedRegion;
productToOrder = this.IpAgoraOrder.constructor.createProductToOrder({
organisation: get(
this.model.params,
'selectedOrganisation.organisationId',
),
...commonProductProps,
country: params.selectedCountry?.code,
datacenter,
});
} else {
productToOrder = this.IpAgoraOrder.constructor.createProductToOrder({
organisation: get(
Expand Down Expand Up @@ -558,7 +682,8 @@ export default class AgoraIpV4OrderController {
return (
this.model.selectedService?.type === PRODUCT_TYPES.vps.typeName ||
this.model.selectedService?.type ===
PRODUCT_TYPES.dedicatedServer.typeName
PRODUCT_TYPES.dedicatedServer.typeName ||
this.model.selectedService?.type === PRODUCT_TYPES.parking.typeName
);
}

Expand All @@ -567,7 +692,8 @@ export default class AgoraIpV4OrderController {
this.model.selectedService?.type ===
PRODUCT_TYPES.privateCloud.typeName ||
this.model.selectedService?.type ===
PRODUCT_TYPES.dedicatedServer.typeName
PRODUCT_TYPES.dedicatedServer.typeName ||
this.model.selectedService?.type === PRODUCT_TYPES.parking.typeName
);
}

Expand Down
Loading

0 comments on commit b713a6e

Please sign in to comment.