Commit 04ee48dd authored by Milan Jaros's avatar Milan Jaros
Browse files

add new version

parent 7d4ad138
......@@ -14,11 +14,11 @@
bl_info = {
"name" : "bheappe",
"author" : "Milan Jaros, Petr Strakos",
"description" : "Rendering-as-a-service",
"blender" : (2, 80, 0),
"version" : (0, 0, 2),
"description" : "Rendering-as-a-Service",
"blender" : (2, 90, 0),
"version" : (1, 3, 1),
"location" : "Addon Preferences panel",
"wiki_url" : "http://blender.it4i.cz/",
"wiki_url" : "https://blender.it4i.cz/",
"category" : "System",
}
......@@ -31,40 +31,17 @@ if 'wheels' in locals():
wheels = importlib.reload(wheels)
wheels.load_wheels()
#pillar = importlib.reload(pillar)
else:
from . import wheels
wheels.load_wheels()
#from . import pillar
log = logging.getLogger(__name__)
# def _monkey_patch_requests():
# """Monkey-patch old versions of Requests.
# This is required for the Mac version of Blender 2.77a.
# """
# import requests
# if requests.__build__ >= 0x020601:
# return
# log.info('Monkey-patching requests version %s', requests.__version__)
# from requests.packages.urllib3.response import HTTPResponse
# HTTPResponse.chunked = False
# HTTPResponse.chunk_left = None
def register():
"""Late-loads and registers the Blender-dependent submodules."""
import sys
#_monkey_patch_requests()
#sys.path.append('raas_lib')
# Support reloading
if '%s.raas_pref' % __name__ in sys.modules:
......@@ -114,8 +91,10 @@ def unregister():
from . import raas_pref
from . import raas_render
async_loop.unregister()
raas_pref.unregister()
raas_render.unregister()
try:
async_loop.unregister()
raas_pref.unregister()
raas_render.unregister()
except RuntimeError:
pass
......@@ -16,6 +16,8 @@
#
# ##### END GPL LICENSE BLOCK #####
# (c) Blender Foundation
"""Manages the asyncio loop."""
import asyncio
......@@ -24,7 +26,6 @@ import concurrent.futures
import logging
import gc
import typing
#import aiohttp
import bpy
......@@ -53,18 +54,6 @@ def setup_asyncio_executor():
loop.set_default_executor(executor)
# loop.set_debug(True)
#from . import raas_server
#import certifi
#import ssl
#import requests
# No more than this many Heappe calls should be made simultaneously
#raas_server.raas_semaphore = asyncio.Semaphore(1, loop=loop)
#raas_server.raas_client = aiohttp.ClientSession(loop=loop, connector=aiohttp.TCPConnector(verify_ssl=False))
#sslcontext = ssl.create_default_context(cafile=certifi.where())
#sslcontext = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
#raas_server.raas_client = requests.session() #aiohttp.ClientSession(loop=loop, connector=aiohttp.TCPConnector(ssl_context=sslcontext))
def kick_async_loop(*args) -> bool:
"""Performs a single iteration of the asyncio event loop.
......@@ -110,9 +99,6 @@ def kick_async_loop(*args) -> bool:
print('{}: resulted in exception'.format(task))
traceback.print_exc()
# for ref in gc.get_referrers(task):
# log.debug(' - referred by %s', ref)
loop.stop()
loop.run_forever()
......
......@@ -11,6 +11,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# (c) Blender Foundation
"""BAT🦇 packing interface for Raas."""
import asyncio
......@@ -125,15 +127,6 @@ class ShamanPacker(shaman.ShamanPacker):
def _get_auth_token(self) -> str:
"""get a token from Raas Server"""
#from ..blender import PILLAR_SERVER_URL
#from ..pillar import blender_id_subclient, uncached_session, SUBCLIENT_ID
#url = urllib.parse.urljoin(PILLAR_SERVER_URL,
# 'raas/jwt/generate-token/%s' % self.manager_id)
#auth_token = blender_id_subclient()['token']
#resp = uncached_session.get(url, auth=(auth_token, SUBCLIENT_ID))
#resp.raise_for_status()
return "resp.text"
......@@ -153,7 +146,6 @@ async def copy(context,
:returns: the path of the packed blend file, and a set of missing sources.
"""
global _running_packer
#from concurrent.futures import ThreadPoolExecutor
loop = asyncio.get_event_loop()
wm = bpy.context.window_manager
......@@ -175,18 +167,12 @@ async def copy(context,
log.debug('awaiting strategise')
wm.raas_status = 'INVESTIGATING'
#executor = ThreadPoolExecutor(max_workers=1)
#futures = []
#futures.append(await loop.run_in_executor(executor, packer.strategise))
await loop.run_in_executor(None, packer.strategise)
log.debug('awaiting execute')
wm.raas_status = 'TRANSFERRING'
#futures.append(await loop.run_in_executor(executor, packer.execute))
await loop.run_in_executor(None, packer.execute)
#await asyncio.wait(futures)
log.debug('done')
wm.raas_status = 'DONE'
......
This diff is collapsed.
This diff is collapsed.
......@@ -16,10 +16,8 @@
#
# ##### END GPL LICENSE BLOCK #####
"""Blender-specific code.
# (c) 2021 IT4Innovations, VSB-TUO
Separated from __init__.py so that we can import & run from non-Blender environments.
"""
import functools
import logging
import os.path
......@@ -66,16 +64,19 @@ class RaasPreferences(AddonPreferences):
options={'HIDDEN', 'SKIP_SAVE'}
)
raas_server: StringProperty(
name='RaaS Server',
default='https://heappe.it4i.cz/raas-open-XX-XX'
)
raas_username: StringProperty(
name='Username',
default='',
options={'HIDDEN', 'SKIP_SAVE'}
default=''
)
raas_password: StringProperty(
name='Password',
default='',
options={'HIDDEN', 'SKIP_SAVE'},
subtype='PASSWORD'
)
......@@ -100,9 +101,15 @@ class RaasPreferences(AddonPreferences):
if self.ok_message:
sub = layout.row()
sub.label(text=self.ok_message, icon='FILE_TICK')
sub.label(text=self.ok_message, icon='FILE_TICK')
box = layout.box()
raas_server = box.split(**factor(0.25), align=True)
raas_server.label(text='Server:')
user_box = raas_server.row(align=True)
user_box.prop(self, 'raas_server', text='')
auth_split = box.split(**factor(0.25), align=True)
auth_split.label(text='Username:')
user_box = auth_split.row(align=True)
......@@ -135,13 +142,6 @@ def ctx_preferences():
def preferences() -> RaasPreferences:
return ctx_preferences().addons[ADDON_NAME].preferences
# class RaasAuthMixin:
# @staticmethod
# def addon_prefs(context):
# addon_prefs = preferences()
# addon_prefs.reset_messages()
# return addon_prefs
class RaasAuthValidate(async_loop.AsyncModalOperatorMixin, Operator):
bl_idname = 'raas_auth.validate'
bl_label = 'Validate'
......
This diff is collapsed.
......@@ -16,6 +16,8 @@
#
# ##### END GPL LICENSE BLOCK #####
# (c) 2021 IT4Innovations, VSB-TUO
import functools
import logging
import typing
......@@ -29,109 +31,28 @@ import requests
log = logging.getLogger(__name__)
# Can be overridden by setting the environment variable RAAS_SERVER_ENDPOINT.
RAAS_SERVER_ENDPOINT = 'https://heappe.it4i.cz/raas/heappe/'
#RAAS_SERVER_ENDPOINT = 'http://localhost:5000/heappe/' #'http://localhost:52005/heappe/'
# # Will become a requests.Session at the first request to Raas.
# requests_session = None
# def get_session():
# """Returns the Requests session, creating it if necessary."""
# global requests_session
# import requests
# if requests_session is not None:
# return requests_session
# requests_session = requests.session()
# # Retry with backoff factor, so that a restart of Raas or hickup
# # in the connection doesn't immediately fail the request.
# retries = requests.packages.urllib3.util.retry.Retry(
# total=10,
# backoff_factor=0.05,
# )
# http_adapter = requests.adapters.HTTPAdapter(max_retries=retries)
# requests_session.mount('https://', http_adapter)
# requests_session.mount('http://', http_adapter)
# # Construct the User-Agent header with Blender and add-on versions.
# try:
# import bpy
# except ImportError:
# blender_version = 'unknown'
# else:
# blender_version = '.'.join(str(component) for component in bpy.app.version)
# from bheappe import bl_info
# addon_version = '.'.join(str(component) for component in bl_info['version'])
# requests_session.headers['User-Agent'] = f'Blender/{blender_version} BHEAPPY-Addon/{addon_version}'
# return requests_session
@functools.lru_cache(maxsize=None)
#@functools.lru_cache(maxsize=None)
def get_endpoint(endpoint_path=None):
"""Gets the endpoint for the authentication API. If the RAAS_SERVER_ENDPOINT env variable
"""Gets the endpoint for the authentication API. If the BHRAAS_SERVER_ENDPOINT env variable
is defined, it's possible to override the (default) production address.
"""
import os
#import os
from . import raas_pref
import urllib.parse
import functools
base_url = os.environ.get('RAAS_SERVER_ENDPOINT')
if base_url:
log.warning('Using overridden Raas url %s', base_url)
else:
base_url = RAAS_SERVER_ENDPOINT
log.info('Using standard Raas url %s', base_url)
base_url = raas_pref.preferences().raas_server + '/heappe/'
# urljoin() is None-safe for the 2nd parameter.
return urllib.parse.urljoin(base_url, endpoint_path)
# async def post_json(endpoint, data_json):
# import requests.exceptions
# url = get_endpoint(endpoint)
# session = get_session()
# try:
# #r = session.post(url, json=data)
# r = session.post(url, data=data_json, headers={'Content-Type': 'application/json'})
# except (requests.exceptions.SSLError,
# requests.exceptions.HTTPError,
# requests.exceptions.ConnectionError) as e:
# msg = 'Exception POSTing to {}: {}'.format(url, e)
# print(msg)
# return None
# if r.status_code == 200:
# return r.text
# err = 'Error code {} from {}: {}'.format(r.status_code, url, r.text)
# print(err)
# return None
#raas_client = None
async def post_json(endpoint, data_json):
url = get_endpoint(endpoint)
# async with raas_client.post(url, data = data_json, headers={'Content-Type': 'application/json'}) as response:
# resp = await response.read()
# return resp
print('Sending request to: %s' % url)
raas_client = requests.session()
response = raas_client.request('POST', url, data = data_json, headers={'Content-Type': 'application/json'})
# if response.status_code == 400:
# print('Server is busy, sending request again 2/3!')
# await asyncio.sleep(5)
# response = raas_client.request('POST', url, data = data_json, headers={'Content-Type': 'application/json'})
# if response.status_code == 400:
# print('Server is busy, sending request again 3/3!')
# await asyncio.sleep(5)
# response = raas_client.request('POST', url, data = data_json, headers={'Content-Type': 'application/json'})
if 200 > response.status_code or 299 < response.status_code:
raise Exception('Http post error: text: %s, status: %d, url: %s' % (response.text, response.status_code, url))
......@@ -141,7 +62,7 @@ async def post_json(endpoint, data_json):
async def post(endpoint, data):
#import json
data_json = json.dumps(data)
data_json = json_dumps(data)
resp = await post_json(endpoint, data_json)
try:
resp_json = json.loads(resp) #.decode('utf-8')
......@@ -163,7 +84,7 @@ async def get_token(username: str, password: str) -> str:
raise Exception('username or password is empty')
#import json
data_json = json.dumps(data)
data_json = json_dumps(data)
resp = await post_json("UserAndLimitationManagement/AuthenticateUserPassword", data_json)
if resp is None or len(resp) != 38:
......@@ -172,43 +93,35 @@ async def get_token(username: str, password: str) -> str:
return resp.replace('"','') #.decode('utf-8')
local_to_server_map = {
"Id" : "id",
"Name" : "name",
"State" : "state",
"Priority" : "priority",
"Project" : "project",
"CreationTime" : "creationTime",
"SubmitTime" : "submitTime",
"StartTime" : "startTime",
"EndTime" : "endTime",
"TotalAllocatedTime" : "totalAllocatedTime",
"AllParameters" : "allParameters",
"Tasks": "tasks",
"Credentials": "credentials",
"PrivateKey": "privateKey",
"ServerHostname": "serverHostname",
"SharedBasepath": "sharedBasepath",
"UserName": "username"
}
def fill_items(dest, src):
for item in dest.__dir__():
if item in src:
dest[item] = src[item]
elif item in local_to_server_map and local_to_server_map[item] in src:
dest[item] = src[local_to_server_map[item]]
else:
dest[item] = None
# This is an asyncio.Semaphore object, which is late-instantiated to be sure
# the asyncio loop has been created properly. On Windows we create a new one,
# which can cause this semaphore to still be linked against the old default
# loop.
# import asyncio
# raas_semaphore = None
# async def post_json(endpoint, data_json):
# """Calls a Raas function.
# A semaphore is used to ensure that there won't be too many
# calls to Raas simultaneously.
# """
# loop = asyncio.get_event_loop()
# # Use explicit calls to acquire() and release() so that we have more control over
# # how long we wait and how we handle timeouts.
# try:
# await asyncio.wait_for(raas_semaphore.acquire(), timeout=10, loop=loop)
# except asyncio.TimeoutError:
# log.info('Waiting for semaphore to call %s', endpoint)
# try:
# await asyncio.wait_for(raas_semaphore.acquire(), timeout=50, loop=loop)
# except asyncio.TimeoutError:
# raise RuntimeError('Timeout waiting for Raas Semaphore!')
# try:
# return await loop.run_in_executor(None, post_json_async, endpoint, data_json)
# finally:
# raas_semaphore.release()
def json_dumps(data):
return json.dumps(data, separators=(',', ':'))
......@@ -61,7 +61,4 @@ def wheel_filename(fname_prefix: str) -> str:
def load_wheels():
load_wheel('blender_asset_tracer', 'blender_asset_tracer')
#load_wheel('lockfile', 'lockfile')
#load_wheel('cachecontrol', 'CacheControl')
#load_wheel('pillarsdk', 'pillarsdk')
load_wheel('blender_asset_tracer', 'blender_asset_tracer')
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment