Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
866 mhunt 1
package com.erggroup.buildtool.ripple;
2
 
3
import org.apache.log4j.Logger;
4
 
5
import com.erggroup.buildtool.smtp.Smtpsend;
6
 
7
import java.sql.SQLException;
8
import java.util.Iterator;
9
import java.util.Vector;
10
 
11
/**entity class holding build exclusion data
12
 */
13
public class BuildExclusion
14
{
15
  /**Logger
16
   * @attribute
17
   */
18
  private static final Logger mLogger = Logger.getLogger(BuildExclusion.class);
19
 
20
  /**identifier
21
   * @attribute
22
   */
23
  private int mId;
24
 
25
  /**root identifier
26
   * @attribute
27
   */
28
  private int mRootId;
29
 
30
  /**root cause
31
   * @attribute
32
   */
33
  private String mRootCause;
34
 
908 mhunt 35
  /**test build instruction
36
   * @attribute
37
   */
38
  private int mTestBuildInstruction;
39
 
866 mhunt 40
  /**in terms of the mChangeType Package field,
41
   * when true indicates the package has not changed, its dependencies potentially have
42
   * in terms of the mRippleField Package field,
43
   * when true indicates the build number will be incremented
44
   * @attribute
45
   */
46
  private boolean mProcessed = false;
47
 
48
  /**constructor
49
   */
908 mhunt 50
  public BuildExclusion(int identifier, int rootIdentifier, String rootCause, int testBuildInstruction )
866 mhunt 51
  {
52
    mLogger.debug("BuildExclusion");
53
    mId = identifier;
868 mhunt 54
    mRootId = dealWithNullRootPvId(identifier, rootIdentifier);
866 mhunt 55
    mRootCause = rootCause;
908 mhunt 56
    mTestBuildInstruction = testBuildInstruction;
866 mhunt 57
  }
58
 
59
  /**sets mProcessed true
60
   */
61
  void process()
62
  {
63
    mLogger.debug("process " + mId);
64
    mProcessed = true;
65
  }
66
 
67
  /**accessor
68
   */
69
  boolean isProcessed()
70
  {
71
    mLogger.debug("isProcessed " + mId);
72
    mLogger.info("isProcessed returned " + mProcessed);
73
    return mProcessed;
74
  }
75
 
76
  /**return true if all attributes match
77
   */
78
  boolean compare( int identifier, int rootIdentifier, String rootCause)
79
  {
80
    mLogger.debug("compare " + mId + ", " + identifier + ", " + rootIdentifier + ", " + rootCause);
81
    boolean retVal = false;
868 mhunt 82
    rootIdentifier = dealWithNullRootPvId(identifier, rootIdentifier);
866 mhunt 83
 
84
    if ( mRootCause == null )
85
    {
86
      if ( mId == identifier && mRootId == rootIdentifier && rootCause == null )
87
      {
88
        retVal = true;
89
      }
90
    }
91
    else
92
    {
93
      if ( mId == identifier && mRootId == rootIdentifier && mRootCause.compareTo(rootCause) == 0 )
94
      {
95
        retVal = true;
96
      }
97
    }
98
 
868 mhunt 99
    mLogger.info("compare returned " + retVal);
866 mhunt 100
    return retVal;
101
  }
102
 
103
  /**return true if mId attribute matches
104
   */
105
  boolean compare( int identifier )
106
  {
107
    mLogger.debug("compare " + mId + ", " + identifier);
108
    boolean retVal = false;
109
 
110
    if ( mId == identifier )
111
    {
112
      retVal = true;
113
    }
114
 
115
    mLogger.info("compare returned " + retVal);
116
    return retVal;
117
  }
118
 
119
  /**runs exclude from build
120
   */
121
  void excludeFromBuild( ReleaseManager rm, int rtag_id ) throws SQLException, Exception
122
  {
123
    mLogger.debug("excludeFromBuild " + mId);
124
    Integer id = mId;
125
    Integer rootId = mRootId;
126
    Integer r = rtag_id;
127
    // a null version and log file is passed to oracle
128
    // the planned version is only needed to remove a planned version from the planned version table
129
    // the ripple engine does not get this far ie it excludes pvs before claiming a version
900 mhunt 130
    // this is the one instance where an existing build failure must be superceded in the database
908 mhunt 131
    rm.excludeFromBuild(id.toString(), null, r.toString(), rootId == -1 ? null : rootId.toString(), mRootCause, null, true, mTestBuildInstruction);
866 mhunt 132
  }
133
 
134
  /**runs exclude from build
135
   */
136
  void includeToBuild( ReleaseManager rm, int rtag_id ) throws SQLException, Exception
137
  {
138
    mLogger.debug("includeToBuild " + mId);
139
    Integer id = mId;
140
    Integer r = rtag_id;
141
    // a null version and log file is passed to oracle
142
    // the planned version is only needed to remove a planned version from the planned version table
143
    // the ripple engine does not get this far ie it excludes pvs before claiming a version
144
    rm.includeToBuild(id.toString(), r.toString());
145
  }
146
 
147
  /**
148
   * return true if the root_pv_id is null (-1) or the it points to a pv_id in the collection
149
   */
150
  boolean isRelevant(Vector<BuildExclusion> buildExclusionCollection)
151
  {
152
    mLogger.debug("isRelevant " + mId);
153
    boolean retVal = false;
154
 
155
    if ( mRootId == -1 )
156
    {
157
      retVal = true;
158
    }
159
    else
160
    {
161
      for (Iterator<BuildExclusion> it = buildExclusionCollection.iterator(); it.hasNext(); )
162
      {
163
        BuildExclusion buildExclusion = it.next();
164
 
165
        if ( buildExclusion.isRelevant( mRootId ) )
166
        {
167
          retVal = true;
168
          break;
169
        }
170
      }
171
    }
172
 
173
    mLogger.info("isRelevant " + mId + " returned " + retVal);
174
    return retVal;
175
  }
176
 
177
  /**
900 mhunt 178
   * return true if the root_pv_id is null (-1)
179
   */
180
  boolean isARootCause()
181
  {
182
    mLogger.debug("isARootCause " + mId);
183
    boolean retVal = false;
184
 
185
    if ( mRootId == -1 )
186
    {
187
      retVal = true;
188
    }
189
 
190
    mLogger.info("isARootCause " + mId + " returned " + retVal);
191
    return retVal;
192
  }
193
 
194
  /**
866 mhunt 195
   * return true if id matches mId
196
   */
197
    private boolean isRelevant(int id)
198
    {
199
      mLogger.debug("isRelevant " + mId + ", " + id);
200
      boolean retVal = false;
201
 
202
      if ( mId == id )
203
      {
204
        retVal = true;
205
      }
206
 
207
      mLogger.info("isRelevant " + mId +  ", " + id + " returned " + retVal);
208
      return retVal;
209
    }
210
 
211
  /**
212
    * user friendly
213
    * does not trigger a storm of emails because a low level package has a build issue
214
    * limit the emails to the low level package
215
    * i.e. only send email if the build exclusion has a null root pv id
216
    * and a non null root cause
217
   */
908 mhunt 218
    public void email(Vector<Package>packageCollection, String mailServer, String mailSender, String release, ReleaseManager releaseManager) throws SQLException, Exception
866 mhunt 219
    {
220
      mLogger.debug("email " + mId);
221
      if ( mRootId == -1 && mRootCause != null )
222
      {
223
        // this is a direct build failure with a ripple engine induced root cause
224
        // send email
225
        Package pkg = null;
226
 
227
        for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
228
        {
229
          Package p = it.next();
230
 
231
          if ( compare(p.mId) )
232
          {
233
            pkg = p;
234
            break;
235
          }
236
        }
237
 
238
        if ( pkg != null )
239
        {
240
          // has the pkg any owners
241
          String owners = pkg.emailInfoNonAntTask();
242
 
243
          if ( owners != null )
244
          {
245
            String body =
246
            "Release: " + release + "<p>" +
247
            "Package: " + pkg.mName + "<p>" + 
248
            mRootCause;
249
 
250
            try
251
            {
252
              Smtpsend.send(
253
              mailServer, // mailServer
254
              mailSender, // source
255
              owners, // target
256
              null, // cc
257
              null, // bcc
258
              "BUILD FAILURE on package " + pkg.mName, // subject
259
              body, // body
260
              null // attachment
261
              );
262
            }
263
            catch( Exception e )
264
            {
265
            }
266
          }
908 mhunt 267
 
268
          // having sent the build failure email, complete a test build if applicable
269
          // this ensures the test build instruction is not processed indefinitely
270
          // as there is no notion of excluding test builds
271
          pkg.completeTestBuild(mailServer, mailSender, releaseManager, release, false);
866 mhunt 272
        }
273
      }
868 mhunt 274
    }
275
 
276
    /**
277
     * hides how a root_pv_id is treated
278
     * only use root_pv_id if not equal to the pv_id
279
     * this is to drive a direct build exclusion in the release manager
280
    */
281
    private int dealWithNullRootPvId( int pvId, int rootPvId )
282
    {
283
      int retVal = rootPvId;
866 mhunt 284
 
868 mhunt 285
      if ( pvId == rootPvId )
286
      {
287
        // force a null root_pv_id in the database
288
        retVal = -1;
289
      }
290
 
291
      return retVal;
866 mhunt 292
    }
293
}