Skip to content

Commit

Permalink
Merge pull request #41 from cloudblue/LITE-27895-add-create-ppr-funct…
Browse files Browse the repository at this point in the history
…ionality-for-regenerate-action

LITE-27895 Add create ppr functionality
  • Loading branch information
d3rky authored Jul 24, 2023
2 parents 781b813 + d64ac54 commit a46dea7
Show file tree
Hide file tree
Showing 32 changed files with 15,054 additions and 224 deletions.
169 changes: 169 additions & 0 deletions connect_ext_ppr/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,172 @@
},
**REQUIRED_SHEETS,
}


BASE_SCHEMA = {
"Resources": [
"Name_EN",
"Description_EN",
"ResourceCategory",
"MPN",
"UOM",
"Measurable",
],
"ServicePlans": [
"OldName_1",
"Name_EN",
"Description_EN",
"PlanCategory",
"ServiceTerms",
"SalesCategory_1",
"BillingPeriodDuration",
"BillingPeriodType",
"AlignBillingOrderWithStatementDay",
"NewDayOfStatement",
"AlignSalesOrderWithStatementDay",
"AllowScheduledChanges",
"BillingPeriodAlignment",
"CotermingPossibilities",
"ExpirationDateAlignedWithEndOfMonth",
"ExpirationDateAlignedWithSubscription",
"FirstBillingPeriodForFree",
"PricePeriod",
"RecurringType",
"AutoRenew",
"RenewOrderInterval",
"AutoRenewPlan",
"AutoRenewPeriod",
"AutoRenewPeriodType",
"BillingAlignmentResellerRedefineAllowed",
"WelcomeNotificationTemplate",
"ExpirationNotificationTemplate",
"ProcessByRatingEngine",
"UpgradePath_1",
"SubscriptionStartDateAfterUpgrade",
"OpUnit_DE",
"ResellerGroupName_1",
"Published", "VendorTimezone",
"MPN",
],
"PlanSwitchPaths": [
"FromPlan",
"ToPlan",
"ImmediateSwitchAllowed",
"SubsStartDateAfterSwitch",
"SubsPeriodChange",
"UpsizeAllowed",
"DownsizeAllowed",
"PartialSwitchAllowed",
"RemoveSwitchPath",
],
"PlanPeriods": [
"ServicePlan",
"Period",
"PeriodType",
"Trial",
"FullRefundPeriod",
"AfterRefundPeriod",
"CancellationType",
"CancellationFeeValue",
"MPN",
],
"ResourceRates": [
"ServicePlan",
"Resource",
"IncUnits",
"MinUnits",
"MaxUnits",
"Measurable",
"ShowInCP",
"ShowInStore",
"ShowZeroRecurringFeeInOrder",
"ShowZeroSetupFeeInOrder",
"ShowZeroOveruseFeeInOrder",
"SetupFeePerUnit",
"RecurringFeePerUnit",
"MPN",
],
"SalesCategories": [
"Name_EN",
"Description_EN",
"ExpandCategory",
"DisplayInCCP",
"ParentCategory",
"Name_DE",
"Description_DE",
],
"ResourceCategories": [
"Name_EN",
"Description_EN",
"ExpandCategory",
"DisplayInCCP",
"ParentCategory",
"Name_DE",
"Description_DE",
],
"DownsizePolicies": [
"ServicePlan",
"Period",
"PeriodType",
"Trial",
"Action",
"ActionPeriod",
"ActionPeriodTimezone",
"ApplicableTo",
],
"CancelationPolicies": [
"ServicePlan",
"Period",
"PeriodType",
"Trial",
"Action",
"ActionPeriod",
"ActionPeriodTimezone",
"ApplicableTo",
],
"NotificationTemplates": [
"TemplateName",
"Language",
"MessageType",
"MessageCategory",
"Subject",
"ToAddr",
"ToName",
"BccAddr",
"FromAddr",
"FromName",
"PDFFileName",
"Active",
"Condition",
"VisibleToReseller",
"Security",
"HTML",
"PlainText",
],
"ResourceDependencies": [
"ChildResource",
"ParentResource",
"DependenceKind",
"DependenceMultiplier",
"MPN",
],
"UpgradeResourceMapping": [
"FromResource",
"ToResource_1",
],
"TermsConditions": [
"Name",
"Acceptance",
"Active",
"Content",
],
"OpUnitServicePlans": [
"OpUnit",
"ServicePlanName",
"TermsConditions_1",
"Published",
"ResellerGroupName_1",
"MPN",
],
}
PPR_FILE_NAME = "PPR_{product_id}_v{version}_{timestamp}.xlsx"
4 changes: 3 additions & 1 deletion connect_ext_ppr/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ class ExtensionHttpError(ExtensionErrorBase):
0: "{client_message}", # Placeholder to use when an api call to connect fails
1: "Object `{obj_id}` not found.",
2: "Object `{obj_id}` already exists, cannot create a new one.",
3: "Database error occurred: {err}.",
3: "Database error occurred.",
4: "Active configuration `{obj_id}` cannot be deleted.",
5: "Configuration `{obj_id}` cannot be deleted, because related deployment is not synced.",
6: "Can not autogenerate a new PPR for deployment {deployment_id}:"
" There must be one `active` configuration file.",
}


Expand Down
8 changes: 5 additions & 3 deletions connect_ext_ppr/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ class Configuration(Model):

PREFIX = 'CFL'

STATE = ConfigurationStateChoices

id = db.Column(db.String(20), primary_key=True)
file = db.Column(db.ForeignKey(File.id))
deployment = db.Column(db.ForeignKey('deployments.id'))
state = db.Column(
db.Enum(ConfigurationStateChoices, validate_strings=True),
default=ConfigurationStateChoices.INACTIVE,
default=STATE.inactive,
)
created_at = db.Column(db.DateTime(), default=datetime.utcnow)
created_by = db.Column(db.JSON)
updated_at = db.Column(db.DateTime(), default=datetime.utcnow)
updated_by = db.Column(db.JSON)

def activate(self):
self.state = ConfigurationStateChoices.ACTIVE
self.state = ConfigurationStateChoices.active

def deleted(self):
self.state = ConfigurationStateChoices.DELETED
self.state = ConfigurationStateChoices.deleted
8 changes: 6 additions & 2 deletions connect_ext_ppr/models/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ class Deployment(Model):

PREFIX = 'DPL'

STATUS = DeploymentStatusChoices

id = db.Column(db.String(20), primary_key=True)
product_id = db.Column(db.String, db.ForeignKey(Product.id))
hub_id = db.Column(db.String(20))
account_id = db.Column(db.String(20))
vendor_id = db.Column(db.String(20))
status = db.Column(
db.Enum(DeploymentStatusChoices, validate_strings=True),
default=DeploymentStatusChoices.PENDING,
default=STATUS.pending,
)
last_sync_at = db.Column(db.DateTime(), default=datetime.utcnow)
created_at = db.Column(db.DateTime(), default=datetime.utcnow)
Expand All @@ -41,12 +43,14 @@ class DeploymentRequest(Model):

PREFIX = 'DPLR'

STATUS = DeploymentRequestStatusChoices

id = db.Column(db.String(20), primary_key=True)
deployment_id = db.Column(db.ForeignKey(Deployment.id))
ppr_id = db.Column(db.String, db.ForeignKey(PPRVersion.id))
status = db.Column(
db.Enum(DeploymentRequestStatusChoices, validate_strings=True),
default=DeploymentRequestStatusChoices.PENDING,
default=STATUS.pending,
)
manually = db.Column(db.Boolean(), default=False)
delegate_l2 = db.Column(db.Boolean(), default=False)
Expand Down
42 changes: 21 additions & 21 deletions connect_ext_ppr/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@


class DeploymentStatusChoices(str, enum.Enum):
PENDING = 'pending'
PROCESSING = 'processing'
SYNCED = 'synced'
pending = 'pending'
processing = 'processing'
synced = 'synced'


class DeploymentRequestStatusChoices(str, enum.Enum):
PENDING = 'pending'
PROCESSING = 'processing'
DONE = 'done'
ERROR = 'error'
ABORTING = 'aborting'
ABORTED = 'aborted'
pending = 'pending'
processing = 'processing'
done = 'done'
error = 'error'
aborting = 'aborting'
aborted = 'aborted'


class TasksStatusChoices(str, enum.Enum):
PENDING = 'pending'
PROCESSING = 'processing'
DONE = 'done'
ERROR = 'error'
ABORTED = 'aborted'
pending = 'pending'
processing = 'processing'
done = 'done'
error = 'error'
aborted = 'aborted'


class TaskTypesChoices(str, enum.Enum):
Expand All @@ -38,13 +38,13 @@ class MimeTypeChoices(str, enum.Enum):


class ConfigurationStateChoices(str, enum.Enum):
ACTIVE = 'active'
INACTIVE = 'inactive'
DELETED = 'deleted'
active = 'active'
inactive = 'inactive'
deleted = 'deleted'


class PPRStatusChoices(str, enum.Enum):
PENDING = 'pending'
PROCESSING = 'processing'
READY = 'ready'
FAILED = 'failed'
pending = 'pending'
processing = 'processing'
ready = 'ready'
failed = 'failed'
2 changes: 2 additions & 0 deletions connect_ext_ppr/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
class File(Model):
__tablename__ = 'files'

MIME_TYPE = MimeTypeChoices

id = db.Column(db.String(20), primary_key=True)
account_id = db.Column(db.String(20))
location = db.Column(db.String(1024))
Expand Down
10 changes: 9 additions & 1 deletion connect_ext_ppr/models/ppr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ def make_version(context):

class PPRVersion(Model):
__tablename__ = 'ppr_version'
__table_args__ = (
db.UniqueConstraint(
"deployment", "version",
name="dpl_version_key",
),
)

PREFIX = 'PPRFL'

STATUS = PPRStatusChoices

id = db.Column(db.String(20), primary_key=True)
file = db.Column(db.ForeignKey(File.id))
deployment = db.Column(db.ForeignKey('deployments.id'))
Expand All @@ -38,7 +46,7 @@ class PPRVersion(Model):
summary = db.Column(db.JSON)
status = db.Column(
db.Enum(PPRStatusChoices, validate_strings=True),
default=PPRStatusChoices.PENDING,
default=PPRStatusChoices.pending,
)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
created_by = db.Column(db.String(20))
4 changes: 3 additions & 1 deletion connect_ext_ppr/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class Task(Model):

PREFIX = 'TSK'

STATUS = TasksStatusChoices

id = db.Column(db.String(30), primary_key=True)
status = db.Column(
db.Enum(TasksStatusChoices, validate_strings=True),
default=TasksStatusChoices.PENDING,
default=STATUS.pending,
)
deployment_request = db.Column(db.ForeignKey(DeploymentRequest.id))
title = db.Column(db.String(100))
Expand Down
6 changes: 5 additions & 1 deletion connect_ext_ppr/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class ConfigurationCreateSchema(NonNullSchema):
file: FileSchema


class ConfigurationSchema(NonNullSchema):
class PPRCreateSchema(NonNullSchema):
file: Optional[FileSchema]


class ConfigurationSchema(ConfigurationCreateSchema):
id: str
file: FileSchema
state: ConfigurationStateChoices
Expand Down
Loading

0 comments on commit a46dea7

Please sign in to comment.