Add logging
[federation.git] / gateway / src / main / java / org / acumos / federation / gateway / adapter / PeerGateway.java
1 /*-
2  * ===============LICENSE_START=======================================================
3  * Acumos
4  * ===================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
6  * ===================================================================================
7  * This Acumos software file is distributed by AT&T and Tech Mahindra
8  * under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *  
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *  
14  * This file is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ===============LICENSE_END=========================================================
19  */
20
21 package org.acumos.federation.gateway.adapter;
22
23 import java.util.List;
24 import java.util.Map;
25 import java.util.HashMap;
26 import java.util.Collections;
27
28 import javax.annotation.PostConstruct;
29 import javax.annotation.PreDestroy;
30
31 import org.acumos.cds.AccessTypeCode;
32 import org.acumos.cds.ValidationStatusCode;
33 import org.acumos.cds.client.ICommonDataServiceRestClient;
34 import org.acumos.cds.domain.MLPArtifact;
35 import org.acumos.cds.domain.MLPPeer;
36 import org.acumos.cds.domain.MLPPeerSubscription;
37 import org.acumos.cds.domain.MLPSolution;
38 import org.acumos.cds.domain.MLPSolutionRevision;
39
40 import org.acumos.federation.gateway.config.EELFLoggerDelegate;
41 import org.acumos.federation.gateway.config.GatewayCondition;
42 import org.acumos.federation.gateway.event.PeerSubscriptionEvent;
43 import org.acumos.federation.gateway.common.Clients;
44 import org.acumos.federation.gateway.common.FederationClient;
45 import org.acumos.federation.gateway.util.Errors;
46 import org.acumos.federation.gateway.util.Utils;
47 import org.acumos.federation.gateway.cds.SubscriptionScope;
48
49 import org.acumos.nexus.client.data.UploadArtifactInfo;
50
51 import org.springframework.beans.factory.BeanInitializationException;
52 import org.springframework.beans.factory.annotation.Autowired;
53 //import org.springframework.scheduling.annotation.Scheduled;
54 import org.springframework.boot.context.properties.ConfigurationProperties;
55 import org.springframework.context.annotation.Scope;
56 import org.springframework.context.annotation.Profile;
57 import org.springframework.context.annotation.Conditional;
58 import org.springframework.context.event.EventListener;
59 import org.springframework.core.env.Environment;
60 import org.springframework.core.io.Resource;
61 import org.springframework.core.task.TaskExecutor;
62 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
63 import org.springframework.stereotype.Component;
64 import org.springframework.web.client.HttpStatusCodeException;
65
66 @Component("peergateway")
67 @Scope("singleton")
68 @Conditional({GatewayCondition.class})
69 public class PeerGateway {
70
71         private final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(PeerGateway.class);
72         private TaskExecutor taskExecutor;
73         @Autowired
74         private Environment env;
75         @Autowired
76         private Clients clients;
77
78         public PeerGateway() {
79                 log.trace(EELFLoggerDelegate.debugLogger, "PeerGateway::new");
80         }
81
82         @PostConstruct
83         public void initGateway() {
84                 log.trace(EELFLoggerDelegate.debugLogger, "initPeerGateway");
85
86                 /* make sure an operator was specified and that it is a declared user */
87                 if (null == this.env.getProperty("federation.operator")) {
88                         throw new BeanInitializationException("Missing 'federation.operator' configuration");
89                 } 
90                 else {
91                         try {
92                                 if (null == this.clients.getCDSClient().getUser(this.env.getProperty("federation.operator"))) {
93                                         log.warn(EELFLoggerDelegate.errorLogger,
94                                                         "'federation.operator' does not point to an existing user");
95                                 }
96                         }
97                         catch (/* HttpStatusCode */Exception dx) {
98                                 log.warn(EELFLoggerDelegate.errorLogger, "failed to verify 'federation.operator' value", dx);
99                         }
100                 }
101
102                 this.taskExecutor = new ThreadPoolTaskExecutor();
103                 ((ThreadPoolTaskExecutor) this.taskExecutor).setCorePoolSize(1);
104                 ((ThreadPoolTaskExecutor) this.taskExecutor).setMaxPoolSize(1);
105                 ((ThreadPoolTaskExecutor) this.taskExecutor).setQueueCapacity(25);
106                 ((ThreadPoolTaskExecutor) this.taskExecutor).initialize();
107
108                 // Done
109                 log.trace(EELFLoggerDelegate.debugLogger, "PeerGateway available");
110         }
111
112         @PreDestroy
113         public void cleanupGateway() {
114                 log.trace(EELFLoggerDelegate.debugLogger, "PeerGateway destroyed");
115         }
116
117         protected String getOwnerId(MLPPeerSubscription theSubscription/*
118                                                                                                                                          * , MLPSolution theSolution
119                                                                                                                                          */) {
120                 String ownerId = theSubscription.getOwnerId();
121                 return ownerId != null ? ownerId : this.env.getProperty("federation.operator");
122         }
123
124         @EventListener
125         public void handlePeerSubscriptionUpdate(PeerSubscriptionEvent theEvent) {
126                 log.info(EELFLoggerDelegate.debugLogger, "received peer subscription update event {}", theEvent);
127                 taskExecutor.execute(
128                                 new PeerGatewayUpdateTask(theEvent.getPeer(), theEvent.getSubscription(), theEvent.getSolutions()));
129         }
130
131         /**
132          * The list of solutions processed here represents the solutions (with respect
133          * to the subscription filter definition) that were reported by the peer as
134          * being updated since the last check.
135          */
136         public class PeerGatewayUpdateTask implements Runnable {
137
138                 private MLPPeer peer;
139                 private MLPPeerSubscription sub;
140                 private List<MLPSolution> solutions;
141
142                 public PeerGatewayUpdateTask(MLPPeer thePeer, MLPPeerSubscription theSub, List<MLPSolution> theSolutions) {
143                         this.peer = thePeer;
144                         this.sub = theSub;
145                         this.solutions = theSolutions;
146                 }
147
148                 public void run() {
149
150                         log.info(EELFLoggerDelegate.debugLogger, "Received peer " + this.peer + " solutions: " + this.solutions);
151                         ICommonDataServiceRestClient cdsClient = PeerGateway.this.clients.getCDSClient();
152                         for (MLPSolution peerSolution : this.solutions) {
153                                 // Check if the Model already exists in the Local Acumos
154                                 MLPSolution localSolution = null;
155                                 log.info(EELFLoggerDelegate.debugLogger, "Processing peer solution {}", peerSolution);
156                                 try {
157                                         localSolution = cdsClient.getSolution(peerSolution.getSolutionId());
158                                 } 
159                                 catch (HttpStatusCodeException scx) {
160                                 try {
161                                         if (!Errors.isCDSNotFound(scx)) {
162                                                 log.error(EELFLoggerDelegate.errorLogger, "Failed to check if solution with id "
163                                                                 + peerSolution.getSolutionId() + " exists locally, skipping for now. Response says " + scx.getResponseBodyAsString(), scx);
164                                                 continue;
165                                         }
166                                 }
167                                 catch (Exception tx) {
168                                         log.error(EELFLoggerDelegate.errorLogger, "Unexpected error while checking not found on "
169                                                                 + peerSolution.getSolutionId(), tx);
170                                         continue;
171                                 }
172
173                                 }
174                                 catch (Exception x) {
175                                         log.error(EELFLoggerDelegate.errorLogger, "Unexpected error while checking if solution with id "
176                                                                 + peerSolution.getSolutionId() + " exists locally, skipping for now.", x);
177                                         continue;
178                                 }
179
180                                 try {
181                                         if (localSolution == null) {
182                                                 log.info(EELFLoggerDelegate.debugLogger, "Solution Id : " + peerSolution.getSolutionId()
183                                                                 + " does not exists locally, adding it to local catalog ");
184                                                 localSolution = createMLPSolution(peerSolution, cdsClient);
185                                         }
186                                         else {
187                                                 log.info(EELFLoggerDelegate.debugLogger, "Solution Id : " + peerSolution.getSolutionId()
188                                                                 + " exists locally, updating local catalog ");
189                                                 localSolution = updateMLPSolution(peerSolution, localSolution, cdsClient);
190                                         }
191
192                                         mapSolution(localSolution, cdsClient);
193                                 }
194                                 catch (Exception x) {
195                                         log.error(EELFLoggerDelegate.errorLogger,
196                                                         "Mapping of acumos solution failed for: " + peerSolution, x);
197                                 }
198                         }
199                 }
200
201                 private MLPSolution createMLPSolution(MLPSolution peerMLPSolution, ICommonDataServiceRestClient cdsClient) {
202                         log.info(EELFLoggerDelegate.debugLogger,
203                                         "Creating Local MLP Solution for peer solution " + peerMLPSolution);
204                         MLPSolution localSolution = new MLPSolution();
205                         localSolution.setSolutionId(peerMLPSolution.getSolutionId());
206                         localSolution.setName(peerMLPSolution.getName());
207                         localSolution.setDescription(peerMLPSolution.getDescription());
208                         localSolution.setAccessTypeCode(AccessTypeCode.PB.toString());
209                         localSolution.setMetadata(peerMLPSolution.getMetadata());
210                         localSolution.setModelTypeCode(peerMLPSolution.getModelTypeCode());
211                         localSolution.setProvider("ATTAcumosInc");
212                         localSolution.setActive(peerMLPSolution.isActive());
213                         localSolution.setToolkitTypeCode(peerMLPSolution.getToolkitTypeCode());
214                         localSolution.setValidationStatusCode(ValidationStatusCode.NV.toString());
215                         localSolution.setCreated(peerMLPSolution.getCreated());
216                         localSolution.setModified(peerMLPSolution.getModified());
217                         localSolution.setOwnerId(getOwnerId(this.sub));
218                         localSolution.setSourceId(this.peer.getPeerId());
219                         try {
220                                 cdsClient.createSolution(localSolution);
221                                 return localSolution;
222                         }
223                         catch (HttpStatusCodeException restx) {
224                                 log.error(EELFLoggerDelegate.errorLogger,
225                                                 "createSolution CDS call failed. CDS message is " + restx.getResponseBodyAsString(), restx);
226                                 return null;
227                         }
228                         catch (Exception x) {
229                                 log.error(EELFLoggerDelegate.errorLogger, "createMLPSolution unexpected failure", x);
230                                 return null;
231                         }
232                 }
233
234                 private MLPSolutionRevision createMLPSolutionRevision(MLPSolutionRevision mlpSolutionRevision,
235                                 ICommonDataServiceRestClient cdsClient) {
236                         MLPSolutionRevision solutionRevision = new MLPSolutionRevision();
237                         solutionRevision.setSolutionId(mlpSolutionRevision.getSolutionId());
238                         solutionRevision.setRevisionId(mlpSolutionRevision.getRevisionId());
239                         solutionRevision.setVersion(mlpSolutionRevision.getVersion());
240                         solutionRevision.setDescription(mlpSolutionRevision.getDescription());
241                         solutionRevision.setOwnerId(getOwnerId(this.sub));
242                         solutionRevision.setMetadata(mlpSolutionRevision.getMetadata());
243                         solutionRevision.setCreated(mlpSolutionRevision.getCreated());
244                         solutionRevision.setModified(mlpSolutionRevision.getModified());
245                         try {
246                                 cdsClient.createSolutionRevision(solutionRevision);
247                                 return solutionRevision;
248                         }
249                         catch (HttpStatusCodeException restx) {
250                                 log.error(EELFLoggerDelegate.errorLogger,
251                                                 "createSolutionRevision CDS call failed. CDS message is " + restx.getResponseBodyAsString(),
252                                                 restx);
253                                 return null;
254                         }
255                         catch (Exception x) {
256                                 log.error(EELFLoggerDelegate.errorLogger, "createSolutionRevision unexpected failure", x);
257                                 return null;
258                         }
259                 }
260
261                 private MLPArtifact createMLPArtifact(String theSolutionId, String theRevisionId, MLPArtifact mlpArtifact,
262                                 ICommonDataServiceRestClient cdsClient) {
263                         MLPArtifact artifact = new MLPArtifact();
264                         artifact.setArtifactId(mlpArtifact.getArtifactId());
265                         artifact.setArtifactTypeCode(mlpArtifact.getArtifactTypeCode());
266                         artifact.setCreated(mlpArtifact.getCreated());
267                         artifact.setDescription(mlpArtifact.getDescription());
268                         artifact.setMetadata(mlpArtifact.getMetadata());
269                         artifact.setModified(mlpArtifact.getModified());
270                         artifact.setName(mlpArtifact.getName());
271                         artifact.setOwnerId(getOwnerId(this.sub));
272                         artifact.setSize(mlpArtifact.getSize());
273                         ;
274                         artifact.setUri(mlpArtifact.getUri());
275                         artifact.setVersion(mlpArtifact.getVersion());
276                         try {
277                                 cdsClient.createArtifact(artifact);
278                                 cdsClient.addSolutionRevisionArtifact(theSolutionId, theRevisionId, mlpArtifact.getArtifactId());
279                                 return artifact;
280                         }
281                         catch (HttpStatusCodeException restx) {
282                                 log.error(EELFLoggerDelegate.errorLogger,
283                                                 "createArtifact CDS call failed. CDS message is " + restx.getResponseBodyAsString(), restx);
284                                 return null;
285                         }
286                         catch (Exception x) {
287                                 log.error(EELFLoggerDelegate.errorLogger, "createArtifact unexpected failure", x);
288                                 return null;
289                         }
290                 }
291
292                 private MLPArtifact copyMLPArtifact(MLPArtifact peerMLPArtifact, MLPArtifact localMLPArtifact) {
293
294                         localMLPArtifact.setArtifactId(peerMLPArtifact.getArtifactId());
295                         localMLPArtifact.setArtifactTypeCode(peerMLPArtifact.getArtifactTypeCode());
296                         localMLPArtifact.setCreated(peerMLPArtifact.getCreated());
297                         localMLPArtifact.setDescription(peerMLPArtifact.getDescription());
298                         localMLPArtifact.setMetadata(peerMLPArtifact.getMetadata());
299                         localMLPArtifact.setModified(peerMLPArtifact.getModified());
300                         localMLPArtifact.setName(peerMLPArtifact.getName());
301                         localMLPArtifact.setOwnerId(getOwnerId(this.sub));
302                         localMLPArtifact.setSize(peerMLPArtifact.getSize());
303                         localMLPArtifact.setUri(peerMLPArtifact.getUri());
304                         localMLPArtifact.setVersion(peerMLPArtifact.getVersion());
305                         return localMLPArtifact;
306                 }
307
308                 private MLPSolution updateMLPSolution(MLPSolution peerMLPSolution, MLPSolution localMLPSolution,
309                                 ICommonDataServiceRestClient cdsClient) {
310                         log.info(EELFLoggerDelegate.debugLogger,
311                                         "Updating Local MLP Solution for peer solution " + peerMLPSolution);
312
313                         if (!peerMLPSolution.getSolutionId().equals(localMLPSolution.getSolutionId()))
314                                 throw new IllegalArgumentException("Local and Peer identifier mismatch");
315
316                         localMLPSolution.setSolutionId(peerMLPSolution.getSolutionId());
317                         localMLPSolution.setName(peerMLPSolution.getName());
318                         localMLPSolution.setDescription(peerMLPSolution.getDescription());
319                         localMLPSolution.setAccessTypeCode(peerMLPSolution.getAccessTypeCode());
320                         localMLPSolution.setMetadata(peerMLPSolution.getMetadata());
321                         localMLPSolution.setModelTypeCode(peerMLPSolution.getModelTypeCode());
322                         localMLPSolution.setProvider(peerMLPSolution.getProvider());
323                         localMLPSolution.setActive(peerMLPSolution.isActive());
324                         localMLPSolution.setToolkitTypeCode(peerMLPSolution.getToolkitTypeCode());
325                         // an update needs to be re-validated
326                         localMLPSolution.setValidationStatusCode(ValidationStatusCode.NV.toString());
327                         {
328                                 String newOwnerId = getOwnerId(this.sub);
329                                 if (!newOwnerId.equals(localMLPSolution.getOwnerId())) {
330                                         // is this solution being updated as part of different/new subscription?
331                                         log.warn(EELFLoggerDelegate.errorLogger, "updating solution " + localMLPSolution.getSolutionId()
332                                                         + " as part of subscription " + this.sub.getSubId() + " triggers an ownership change");
333                                 }
334                                 localMLPSolution.setOwnerId(newOwnerId);
335                         }
336
337                         {
338                                 String newSourceId = this.peer.getPeerId();
339                                 if (!newSourceId.equals(localMLPSolution.getSourceId())) {
340                                         // we will see this if a solution is available in more than one peer
341                                         log.warn(EELFLoggerDelegate.errorLogger, "updating solution " + localMLPSolution.getSolutionId()
342                                                         + " as part of subscription " + this.sub.getSubId() + " triggers a source change");
343                                 }
344                                 localMLPSolution.setSourceId(newSourceId);
345                         }
346
347                         try {
348                                 cdsClient.updateSolution(localMLPSolution);
349                                 return localMLPSolution;
350                         }
351                         catch (HttpStatusCodeException restx) {
352                                 log.error(EELFLoggerDelegate.errorLogger,
353                                                 "updateSolution CDS call failed. CDS message is " + restx.getResponseBodyAsString(), restx);
354                                 return null;
355                         }
356                         catch (Exception x) {
357                                 log.error(EELFLoggerDelegate.errorLogger, "updateSolution unexpected failure", x);
358                                 return null;
359                         }
360                 }
361
362                 /**
363                  * Here comes the core process of updating a local solution's related
364                  * information with what is available from a peer.
365                  * 
366                  * @param theSolution
367                  *            the local solution who's related information (revisions and
368                  *            artifacts) we are trying to sync
369                  * @param cdsClient
370                  *            CDS client to use in the process
371                  * @throws Exception
372                  *             any error related to CDS and peer interaction
373                  */
374                 protected void mapSolution(MLPSolution theSolution, ICommonDataServiceRestClient cdsClient) throws Exception {
375
376                         FederationClient fedClient = clients.getFederationClient(this.peer.getApiUrl());
377
378                         // get revisions
379                         List<MLPSolutionRevision> peerRevisions = null;
380                         try {
381                                 peerRevisions = (List<MLPSolutionRevision>) fedClient.getSolutionRevisions(theSolution.getSolutionId())
382                                                 .getContent();
383                         }
384                         catch (Exception x) {
385                                 log.warn(EELFLoggerDelegate.errorLogger, "Failed to retrieve acumos revisions for solution "
386                                                 + theSolution.getSolutionId() + " from peer " + this.peer, x);
387                                 throw x;
388                         }
389
390                         // this should not happen as any solution should have at least one
391                         // revision (but that's an assumption on how on-boarding works)
392                         if (peerRevisions == null || peerRevisions.size() == 0) {
393                                 log.warn(EELFLoggerDelegate.debugLogger, "No revisions were retrieved");
394                                 return;
395                         }
396
397                         // check if we have locally the latest revision available on the peer
398                         // TODO: this is just one possible policy regarding the handling of
399                         // such a mismatch
400                         List<MLPSolutionRevision> cdsRevisions = Collections.EMPTY_LIST;
401                         try {
402                                 cdsRevisions = cdsClient.getSolutionRevisions(theSolution.getSolutionId());
403                         }
404                         catch (HttpStatusCodeException restx) {
405                                 if (!Errors.isCDSNotFound(restx)) {
406                                         log.error(EELFLoggerDelegate.errorLogger,
407                                                         "getSolutionRevisions CDS call failed. CDS message is " + restx.getResponseBodyAsString(),
408                                                         restx);
409                                         throw restx;
410                                 }
411                         }
412                         final List<MLPSolutionRevision> localRevisions = cdsRevisions;
413
414                         // map peer revisions to local ones; new peer revisions have a null mapping
415                         Map<MLPSolutionRevision, MLPSolutionRevision> peerToLocalRevisions =
416                                         /*
417                                          * Elegant but toMap uses map merging which does not allow null values
418                                          * peerRevisions .stream() .collect( Collectors.toMap(...)
419                                          */
420                                         new HashMap<MLPSolutionRevision, MLPSolutionRevision>();
421                         peerRevisions.forEach(peerRevision -> peerToLocalRevisions.put(peerRevision,
422                                         localRevisions.stream()
423                                                         .filter(localRevision -> localRevision.getRevisionId().equals(peerRevision.getRevisionId()))
424                                                         .findFirst().orElse(null)));
425
426                         for (Map.Entry<MLPSolutionRevision, MLPSolutionRevision> revisionEntry : peerToLocalRevisions.entrySet()) {
427                                 MLPSolutionRevision peerRevision = revisionEntry.getKey(), localRevision = revisionEntry.getValue();
428                                 // get peer artifacts
429                                 List<MLPArtifact> peerArtifacts = null;
430                                 try {
431                                         peerArtifacts = (List<MLPArtifact>) fedClient
432                                                         .getArtifacts(theSolution.getSolutionId(), peerRevision.getRevisionId()).getContent();
433                                 }
434                                 catch (Exception x) {
435                                         log.warn(EELFLoggerDelegate.errorLogger, "Failed to retrieve peer acumos artifacts", x);
436                                         throw x;
437                                 }
438
439                                 List<MLPArtifact> cdsArtifacts = Collections.EMPTY_LIST;
440                                 if (localRevision == null) {
441                                         localRevision = createMLPSolutionRevision(peerRevision, cdsClient);
442                                 }
443                                 else {
444                                         try {
445                                                 cdsArtifacts = cdsClient.getSolutionRevisionArtifacts(theSolution.getSolutionId(),
446                                                                 localRevision.getRevisionId());
447                                         }
448                                         catch (HttpStatusCodeException restx) {
449                                                 if (!Errors.isCDSNotFound(restx)) {
450                                                         log.error(EELFLoggerDelegate.errorLogger,
451                                                                         "getArtifact CDS call failed. CDS message is " + restx.getResponseBodyAsString(),
452                                                                         restx);
453                                                         throw restx;
454                                                 }
455                                         }
456                                 }
457
458                                 final List<MLPArtifact> localArtifacts = cdsArtifacts;
459                                 // map the artifacts
460                                 // TODO: track deleted artifacts
461                                 Map<MLPArtifact, MLPArtifact> peerToLocalArtifacts = new HashMap<MLPArtifact, MLPArtifact>();
462                                 peerArtifacts.forEach(peerArtifact -> peerToLocalArtifacts.put(peerArtifact, localArtifacts.stream()
463                                                 .filter(localArtifact -> localArtifact.getArtifactId().equals(peerArtifact.getArtifactId()))
464                                                 .findFirst().orElse(null)));
465
466                                 for (Map.Entry<MLPArtifact, MLPArtifact> artifactEntry : peerToLocalArtifacts.entrySet()) {
467                                         MLPArtifact peerArtifact = artifactEntry.getKey(), localArtifact = artifactEntry.getValue();
468                                         boolean doUpdate = false;
469
470                                         if (localArtifact == null) {
471                                                 localArtifact = createMLPArtifact(theSolution.getSolutionId(), localRevision.getRevisionId(),
472                                                                 peerArtifact, cdsClient);
473                                         }
474                                         else {
475                                                 if (!peerArtifact.getVersion().equals(localArtifact.getVersion())) {
476                                                         // update local artifact
477                                                         copyMLPArtifact(peerArtifact, localArtifact);
478                                                         doUpdate = true;
479                                                 }
480                                         }
481
482                                         boolean doContent = (SubscriptionScope.Full == SubscriptionScope.forCode(this.sub.getScopeType()));
483                                         if (doContent) {
484                                                 // TODO: we are trying to access the artifact by its identifier which
485                                                 // is fine in the common case but the uri specified in the artifact
486                                                 // data is a more flexible approach.
487                                                 Resource artifactContent = null;
488                                                 try {
489                                                         artifactContent = fedClient.downloadArtifact(peerArtifact.getArtifactId());
490                                                 }
491                                                 catch (Exception x) {
492                                                         log.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve acumos artifact content", x);
493                                                 }
494
495                                                 UploadArtifactInfo uploadInfo = null;
496                                                 if (artifactContent != null) {
497                                                         try {
498                                                                 uploadInfo = PeerGateway.this.clients.getNexusClient()
499                                                                                 .uploadArtifact(PeerGateway.this.env.getProperty("nexus.groupId"),
500                                                                                                 localArtifact.getName(), /* probably wrong */
501                                                                                                 localArtifact.getVersion(), "", /* should receive this from peer */
502                                                                                                 artifactContent.contentLength(), artifactContent.getInputStream());
503                                                         }
504                                                         catch (Exception x) {
505                                                                 log.error(EELFLoggerDelegate.errorLogger,
506                                                                                 "Failed to push artifact content to local Nexus repo", x);
507                                                         }
508                                                 }
509
510                                                 if (uploadInfo != null) {
511                                                         // update artifact with local repo reference
512                                                         localArtifact.setUri(uploadInfo.getArtifactMvnPath());
513                                                         // the artifact info will need to be updated with local content uri
514                                                         doUpdate = true;
515                                                 }
516                                         }
517
518                                         if (doUpdate) {
519                                                 try {
520                                                         cdsClient.updateArtifact(localArtifact);
521                                                 }
522                                                 catch (HttpStatusCodeException restx) {
523                                                         log.error(EELFLoggerDelegate.errorLogger,
524                                                                         "updateArtifact CDS call failed. CDS message is " + restx.getResponseBodyAsString(),
525                                                                         restx);
526                                                 }
527                                         }
528                                 }
529                         }
530                 } // mapSolution
531         }
532 }