How to get the project id in IBM Watson? - ibm-watson

How do I get the project ID of my project in IBM Watson so that I access a data source?

This is documented here : https://www.ibm.com/docs/en/cloud-paks/cp-data/4.0?topic=lib-watson-studio-python
from ibm_watson_studio_lib import access_project_or_space
wslib = access_project_or_space()
project_name = wslib.here.get_name()
wslib.show(project_name)
project_id = wslib.here.get_ID()
wslib.show(project_id)
Example
The old project-lib has been deprecated. See Deprecation Announcement https://www.ibm.com/docs/en/cloud-paks/cp-data/4.0?topic=notebook-using-project-lib-python-deprecated

In the project homepage url, the project id is the alphanumeric string just after the '/proj/". Copy it and use it as the project id.

Related

Report to find objects of a segw project and put them on a request

I'm new in SAP and during my practicing I came up with a 'problem': when I was transporting my project to another system I had to manually include some objects that were in other requests.
So now I'm trying to make a report to join all the objects related to a segw project in a single request. My idea is passing the Project ID or name to my report find the objects, create a request and put all of them into it.
I've already found something. When creating a segw project and generate it, the request has:
- Class (ABAP objects) with the DPC and MPC
- SAP Gateway Business Suite Enablement - Model
- SAP Gateway BSE - Service Builder Project
- SAP Gateway Business Suite Enablement - Service
I've found two tables that help me to get DPC and MPC objects:
TMDIR, VSEOCLASS.
Am I in the right path? Is there a way to find all related objects to the project or I'll need to find them separately like the DPC and MPC I've already found?
Thanks!
Assuming all your SEGW objects reside in a single package which is usually the case when you create SEGW project from scratch:
DATA: l_trkorr TYPE trkorr,
l_package TYPE devclass VALUE 'ZSEGW_P'.
cl_pak_package_queries=>get_all_subpackages( EXPORTING im_package = l_package
IMPORTING et_subpackages = DATA(lt_descendant) ).
INSERT VALUE cl_pak_package_queries=>ty_subpackage_info( package = l_package ) INTO TABLE lt_descendant.
SELECT pgmid, object, obj_name FROM tadir
INTO TABLE #DATA(lt_segw_objects)
FOR ALL ENTRIES IN #lt_descendant
WHERE devclass = #lt_descendant-package.
DATA(instance) = cl_adt_cts_management=>create_instance( ).
LOOP AT lt_segw_objects ASSIGNING FIELD-SYMBOL(<fs_obj>).
TRY.
instance->insert_objects_in_wb_request( EXPORTING pgmid = <fs_obj>-pgmid
object = <fs_obj>-object
obj_name = CONV trobj_name( <fs_obj>-obj_name )
IMPORTING result = DATA(result)
request = DATA(request)
CHANGING trkorr = l_trkorr ).
CATCH cx_adt_cts_insert_error.
ENDTRY.
ENDLOOP.
This snippet creates transport request with number l_trkorr and as soon as this var is not changed put all remainign objects in the same request.
WARNING: this will not work if the objects are locked (in another request) and will give you cx_adt_cts_insert_error exception. There is no way to unlock objects programmatically, only via SE03 tool.

How to log data in DNN admin log or server event log

I simply want to debug a controller but I can't watch the variables I get from 2sxc functions.
I tried to log varables via Log4Net writting :
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(MyClassName));
but the type ILog is not known in a 2sxc controller. Am I missing a reference?
I also found this snippet:
using DotNetNuke.Services.Log.EventLog;
var objEventLog = new EventLogController();
objEventLog.AddLog("Sample Message", "Something Interesting Happened!", PortalSettings, UserId, EventLogController.EventLogType.ADMIN_ALERT)
But I don't know what to send to "PortalSettings" and I don't any clue in the helpers of the 2sxc programming interface.
How do you guys debug 2sxc controllers and log events (not only for debuging)?
Thank you for your help!
Credit of these snippets: Scott McCulloch (https://www.smcculloch.com/code/logging-to-the-dnn-event-log)
This gives part of the answer: http://www.dnnsoftware.com/community-blog/cid/141723/using-log4net-with-dotnetnuke. And, it looks like the namespace is DotNetNuke.Instrumentation.
As for PortalSettings, that's the portal settings for your portal. I think that you'd need to reference DotNetNuke.Entities.Portals, and then use PortalController to retrieve the portal settings object.
Joe Craig's previous post helped me a lot.
So, in a 2sxc application, I now can log in the DNN event log (not the Windows one):
#using DotNetNuke.Services.Log.EventLog;
#using DotNetNuke.Entities.Portals;
#{
var aujourdhui = DateTime.Now;
var objEventLog = new EventLogController();
PortalSettings PortalSettings = new PortalSettings();
objEventLog.AddLog("Debug info", "Variable \"Aujourdhui\" contains: " + aujourdhui.ToString("dddd d MMMM yyyy"), PortalSettings, #Dnn.User.UserID, EventLogController.EventLogType.ADMIN_ALERT);
}
The only little problem is that this PortalSettings returns the first portal even if my 2sxc app runs on the second portal (id=1). I must be missing something. But for now and what I need (debugging), thats Ok for me!

How to set parent Id in version 3 of google drive API?

I am currently using version2 of API. Now, I want to switch to version3. I want to set the parentId in this version. What changes should I make in below line of code to do so?
I don't think this function was changed because it wasn't mentioned in the Migration Guide for v3. You can see the snippet here in Inserting a file in a folder:
String folderId = "0BwwA4oUTeiV1TGRPeTVjaWRDY1E";
File fileMetadata = new File();
fileMetadata.setName("photo.jpg");
fileMetadata.setParents(Collections.singletonList(folderId));
java.io.File filePath = new java.io.File("files/photo.jpg");

Why isn't Modernizr loading in Drupal 7 info file?

name = Lucas description = Drupal-thema gemaakt voor de kinderafdeling
AZ St-Lucas Gent. package = Core version = VERSION core = 7.x
stylesheets[all][] = style.css
scripts[] = scripts/lib/modernizr.js
settings[garland_width] = fluid
; Information added by drupal.org packaging script on 2013-02-20
version = "7.x" project = "drupal" datestamp = "1361393684"
It's possible that your JS file isn't at that location, meaning that Drupal will automatically avoid generating a 404 by omitting the call to the non-existent file.
You could also rely on the Modernizr Drupal module and it takes care of placement for you. It can also keep Modernizr up to date more easily by supplying you with a drush command to refresh the file, along with a nice API that allows for custom builds to be generated more conveniently. Check it out!
see the installation instructions to use modernizr http://drupal.org/project/modernizr

AppEngine: Get current serving application version

Is there a simple way to get the current serving application version in AppEngine?
os.environ['CURRENT_VERSION_ID']
String version = SystemProperty.version.get();
String applicationVersion = SystemProperty.applicationVersion.get();
This is the syntax:
public static final SystemProperty applicationVersion
The major version number for the currently running version of the application plus a timestamp at which it was deployed. Has the key, "com.google.appengine.application.version".
See here
PS. One puzzle still remains. What does timestamp next to version means and how to read it??
EDIT: Here is the key to the mystery.
Date UploadDate = new Date(Long.parseLong(
applicationVersion.substring(applicationVersion.lastIndexOf(‌​".")+1))
/ (2 << 27) * 1000);
For Python (GAE SDK release: "1.4.2")
version_id = self.request.environ["CURRENT_VERSION_ID"].split('.')[1]
timestamp = long(version_id) / pow(2,28)
version = datetime.datetime.fromtimestamp(timestamp).strftime("%d/%m/%y %X")
See http://groups.google.com/group/google-appengine-python/browse_thread/thread/f86010e7cf3c71b4
from google.appengine.api import modules
modules.get_current_version_name()
Source: https://cloud.google.com/appengine/docs/python/modules/functions
For nodejs, I am not sure if this is documented.
process.env.GAE_VERSION
You can also access the process' environment variables:
GAE_VERSION
which is available when you deploy (gcloud app deploy) using the flag --version
For those who want an update, environment variables set for a GAE instance as of September 2020:
GAE_VERSION is the one that seems to answer the original question.
Google doc:
https://cloud.google.com/appengine/docs/standard/python3/runtime#environment_variables
The following environment variables are set by the runtime:
Environment variable Description
GAE_APPLICATION The ID of your App Engine application. This ID is prefixed with 'region code~' such as 'e~' for applications deployed in Europe.
GAE_DEPLOYMENT_ID The ID of the current deployment.
GAE_ENV The App Engine environment. Set to standard.
GAE_INSTANCE The ID of the instance on which your service is currently running.
GAE_MEMORY_MB The amount of memory available to the application process, in MB.
GAE_RUNTIME The runtime specified in your app.yaml file.
GAE_SERVICE The service name specified in your app.yaml file. If no service name is specified, it is set to default.
GAE_VERSION The current version label of your service.
GOOGLE_CLOUD_PROJECT The Cloud project ID associated with your application.
PORT The port that receives HTTP requests.
Based on my experiments today, there are two os.environ variables that you can use to get the current app version:
os.environ['GAE_VERSION']: the version name only
os.environ['CURRENT_VERSION_ID']: a unique version identifier composed of {version name}.{deployment id}, which is equivalent to os.environ['GAE_VERSION'] + '.' + os.environ['GAE_DEPLOYMENT_ID']
It appears that the so-called "deployment id" can be right-shifted 28 bits to get a timestamp in epoch seconds (as other answers already described).
For example: I deployed version "101" of my app at 2021-03-04T00:17:12Z and I'm seeing the following values:
os.environ['GAE_VERSION']: '101'
os.environ['CURRENT_VERSION_ID']: '101.433474146608888597'
os.environ['GAE_DEPLOYMENT_ID']: '433474146608888597'
You can use the following code to get the version name and timestamp from os.environ['CURRENT_VERSION_ID']:
>>> import os
>>> import datetime
>>> version_id = os.environ['CURRENT_VERSION_ID'] # example: '101.433474146608888597'
>>> name, ts = version_id.split('.')
>>> dt = datetime.datetime.utcfromtimestamp(int(ts) >> 28))
>>> dt.isoformat()
'2021-03-04T00:17:12'
Disclaimer: Most of this functionality is undocumented and the deployment ID format may be subject to change.

Resources