Skip to content

Commit

Permalink
fix: added minor fixes to api re-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
anaik91 committed Sep 22, 2023
1 parent 8efa176 commit ef438a2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
**/node_modules/**
**/generated/**

target/
export/
.settings
.project
.classpath
Expand Down
61 changes: 35 additions & 26 deletions tools/target-server-validator/apigee_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ def get_api(self, api_name):
headers = self.auth_header.copy()
response = requests.request("GET", url, headers=headers)
if response.status_code == 200:
return True
revision = response.json().get('revision', ['1'])
return True, revision
else:
return False
return False, None

def create_api(self, api_name, proxy_bundle_path):
url = f"{self.baseurl}/apis?action=import&name={api_name}&validate=true" # noqa
Expand Down Expand Up @@ -175,16 +176,18 @@ def deploy_api(self, env, api_name, api_rev):
print(response.text)
return False

def deploy_api_bundle(self, env, api_name, proxy_bundle_path, api_rev=1, api_force_redeploy=False): # noqa
def deploy_api_bundle(self, env, api_name, proxy_bundle_path, api_force_redeploy=False): # noqa
api_deployment_retry = 60
api_deployment_sleep = 5
api_deployment_retry_count = 0
api_exists = False
if self.get_api(api_name):
get_api_status, api_revs = self.get_api(api_name)
if get_api_status:
api_exists = True
api_rev = api_revs[-1]
print(
f"Proxy with name {api_name} already exists in Apigee Org {self.org}" # noqa
f"Proxy with name {api_name} with revision {api_rev} already exists in Apigee Org {self.org}" # noqa
)
api_exists = True
if api_force_redeploy:
api_exists = False
if not api_exists:
Expand All @@ -198,29 +201,35 @@ def deploy_api_bundle(self, env, api_name, proxy_bundle_path, api_rev=1, api_for
print(f"ERROR : Proxy {api_name} import failed !!! ")
return False
if api_exists:
if self.deploy_api(env, api_name, api_rev):
print(
f"Proxy with name {api_name} has been deployed to {env} in Apigee Org {self.org}" # noqa
)
while api_deployment_retry_count < api_deployment_retry:
if self.get_api_revisions_deployment(
if self.get_api_revisions_deployment(
env, api_name, api_rev
):
print(
f"Proxy {api_name} active in runtime after {api_deployment_retry_count*api_deployment_sleep} seconds " # noqa
)
return True
else:
print(
f"Checking API deployment status in {api_deployment_sleep} seconds" # noqa
)
sleep(api_deployment_sleep)
api_deployment_retry_count += 1
print(f"INFO : Proxy {api_name} already active in to {env} in Apigee Org {self.org} !") # noqa
return True
else:
print(
f"ERROR : Proxy deployment to {env} in Apigee Org {self.org} Failed !!" # noqa
)
return False
if self.deploy_api(env, api_name, api_rev):
print(
f"Proxy with name {api_name} has been deployed to {env} in Apigee Org {self.org}" # noqa
)
while api_deployment_retry_count < api_deployment_retry:
if self.get_api_revisions_deployment(
env, api_name, api_rev
):
print(
f"Proxy {api_name} active in runtime after {api_deployment_retry_count*api_deployment_sleep} seconds " # noqa
)
return True
else:
print(
f"Checking API deployment status in {api_deployment_sleep} seconds" # noqa
)
sleep(api_deployment_sleep)
api_deployment_retry_count += 1
else:
print(
f"ERROR : Proxy deployment to {env} in Apigee Org {self.org} Failed !!" # noqa
)
return False

def get_api_vhost(self, vhost_name, env):
if self.apigee_type == "opdk":
Expand Down
3 changes: 1 addition & 2 deletions tools/target-server-validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def main():
cfg["validation"]["api_env"],
cfg["validation"]["api_name"],
f"{bundle_path}/{cfg['validation']['api_name']}.zip",
1,
cfg["validation"].getboolean("api_force_redeploy", False)
):
print(f"Proxy: {cfg['validation']['api_name']} deployment failed.")
Expand All @@ -162,7 +161,7 @@ def main():
)
vhost_domain_name = cfg["validation"]["api_hostname"]
vhost_ip = cfg["validation"].get("api_ip", "").strip()
api_url = f"https://{vhost_domain_name}/validate_target_server"
api_url = f"https://{vhost_domain_name}/validate-target-server"
final_report = []
_cached_hosts = {}

Expand Down

0 comments on commit ef438a2

Please sign in to comment.