Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs and release #188

Merged
merged 10 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docker/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ ADD ./k8s_tools.py /root/
ADD ./python/dist/pcloud-0.1.1-py2-none-any.whl /tmp/
#RUN pip install /tmp/pcloud-0.1.1-py2-none-any.whl && \
# rm /tmp/pcloud-0.1.1-py2-none-any.whl
RUN pip install /tmp/pcloud-0.1.1-py2-none-any.whl
RUN pip install /tmp/pcloud-0.1.1-py2-none-any.whl && \
pip install opencv-python && \
apt-get install -y libgtk2.0-dev

CMD ["paddle_k8s"]
EOF
Expand Down
2 changes: 1 addition & 1 deletion go/paddlecloud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (p *GetCommand) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{
}

func workers(jobname string) error {
var queryMap url.Values
queryMap := url.Values{}
queryMap.Add("jobname", jobname)
respBody, err := restclient.GetCall(Config.ActiveConfig.Endpoint+"/api/v1/workers/", queryMap)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/paddlecloud/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (p *LogsCommand) Execute(_ context.Context, f *flag.FlagSet, _ ...interface
return subcommands.ExitFailure
}

queryMap := make(url.Values)
queryMap := url.Values{}
queryMap.Add("n", strconv.FormatInt(int64(p.n), 10))
queryMap.Add("w", p.w)
queryMap.Add("jobname", f.Arg(0))
Expand Down
2 changes: 2 additions & 0 deletions paddlecloud/paddlecloud/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@
}
# where cephfs root is mounted when using cephfs storage service
STORAGE_PATH="/pfs"
# HACK: define use HDFS or CEPHFS, in cephfs mode jobpath will be /pfs/jobs/[jobname]
STORAGE_MODE="HDFS"

# ===================== Docker image registry =====================
JOB_DOCKER_IMAGE = {
Expand Down
62 changes: 36 additions & 26 deletions paddlecloud/paddlejob/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def post(self, request, format=None):
host_path = cfg["host_path"]
else:
mount_path = cfg["mount_path"] % (dc, username)
host_path = cfg["host_path"] % username
host_path = cfg["host_path"]

volumes.append(volume.get_volume_config(
fstype = fstype,
Expand All @@ -95,12 +95,20 @@ def post(self, request, format=None):
# jobPackage validation: startwith /pfs
# NOTE: job packages are uploaded to /pfs/[dc]/home/[user]/jobs/[jobname]
job_name = obj.get("name", "paddle-cluster-job")
package_in_pod = os.path.join("/pfs/%s/home/%s"%(dc, username), "jobs", job_name)
if settings.STORAGE_MODE == "CEPHFS":
package_in_pod = os.path.join("/pfs/%s/home/%s"%(dc, username), "jobs", job_name)
elif settings.STORAGE_MODE == "HDFS":
package_in_pod = obj.get("jobPackage")

logging.info("current package: %s", package_in_pod)
# package must be ready before submit a job
current_package_path = package_in_pod.replace("/pfs/%s/home"%dc, settings.STORAGE_PATH)
if not os.path.exists(current_package_path):
return utils.error_message_response("error: package not exist in cloud")
current_package_path = package_in_pod.replace("/pfs/%s/home/%s"%(dc, username), settings.STORAGE_PATH)
if not os.path.exists(current_package_path):
return utils.error_message_response("package not exist in cloud: %s"%current_package_path)
logging.info("current package in pod: %s", current_package_path)


# use default images
if not job_image :
Expand Down Expand Up @@ -228,6 +236,19 @@ def get(self, request, format=None):
"""
Get logs for jobs
"""
def _get_pod_log(api_client, namespace, pod_name, num_lines):
try:
if num_lines:
pod_log = client.CoreV1Api(api_client=api_client)\
.read_namespaced_pod_log(
pod_name, namespace, tail_lines=int(num_lines))
else:
pod_log = client.CoreV1Api(api_client=api_client)\
.read_namespaced_pod_log(i.metadata.name, namespace)
return pod_log
except ApiException, e:
return str(e)

username = request.user.username
namespace = notebook.utils.email_escape(username)
api_client = notebook.utils.get_user_api_client(username)
Expand All @@ -240,22 +261,10 @@ def get(self, request, format=None):
if not worker:
for i in job_pod_list.items:
total_job_log = "".join((total_job_log, "==========================%s==========================" % i.metadata.name))
if num_lines:
pod_log = client.CoreV1Api(api_client=api_client)\
.read_namespaced_pod_log(
i.metadata.name, namespace, tail_lines=int(num_lines))
else:
pod_log = client.CoreV1Api(api_client=api_client)\
.read_namespaced_pod_log(i.metadata.name, namespace)
pod_log = _get_pod_log(api_client, namespace, i.metadata.name, num_lines)
total_job_log = "\n".join((total_job_log, pod_log))
else:
if num_lines:
pod_log = client.CoreV1Api(api_client=api_client)\
.read_namespaced_pod_log(worker, namespace, tail_lines=int(num_lines))
else:
pod_log = client.CoreV1Api(api_client=api_client)\
.read_namespaced_pod_log(worker, namespace)
total_job_log = pod_log
total_job_log = _get_pod_log(api_client, namespace, worker, num_lines)
return utils.simple_response(200, total_job_log)

class WorkersView(APIView):
Expand Down Expand Up @@ -374,16 +383,17 @@ def get(self, request, format=None):
# validate list path must be under user's dir
path_parts = file_path.split(os.path.sep)
msg = ""
if len(path_parts) <= 1:
msg = "path must start with /pfs"
if len(path_parts) >= 2 and path_parts[1] != "pfs":
msg = "path must start with /pfs"
if len(path_parts) >= 3 and path_parts[2] not in settings.DATACENTERS.keys():
msg = "no datacenter "+path_parts[2]
if len(path_parts) >= 4 and path_parts[3] != "home":
msg = "path must like /pfs/[dc]/home/[user]"
if len(path_parts) >= 5 and path_parts[4] != request.user.username:
if len(path_parts) < 5:
msg = "path must like /pfs/[dc]/home/[user]"
else:
if path_parts[1] != "pfs":
msg = "path must start with /pfs"
if path_parts[2] not in settings.DATACENTERS.keys():
msg = "no datacenter "+path_parts[2]
if path_parts[3] != "home":
msg = "path must like /pfs/[dc]/home/[user]"
if path_parts[4] != request.user.username:
msg = "not a valid user: " + path_parts[4]
if msg:
return Response({"msg": msg})

Expand Down